?action=something

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

kakapeepee
Forum Newbie
Posts: 14
Joined: Wed Oct 04, 2006 8:40 am

?action=something

Post by kakapeepee »

how can i make something like

file.php?action=soemthing

something will sure be a function, but it is that ?action= that i donno how to do it
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

kakapeepee
Forum Newbie
Posts: 14
Joined: Wed Oct 04, 2006 8:40 am

Post by kakapeepee »

lol it's ok i know alot about php, but it is this thing i know nothing about, i dont need an intro, just inform me about this thing im asking for, and it will work with me, be sure
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

do you know about superglobals?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

echo $_GET['action'];
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

You need to elaborate... what do you mean? How do you get the ?action=something in the url?
If so... there's a few ways...

Code: Select all

<form method="get" action="#">
 <input type="hidden" name="action" value="something">
 <input type="submit" value="Submit">
</form>

Code: Select all

<a href="http://www.somesite.com?action=something">Click Here</a>
If you mean how do you access that variable, use $_GET['action']
Last edited by Luke on Wed Oct 04, 2006 11:16 am, edited 1 time in total.
kakapeepee
Forum Newbie
Posts: 14
Joined: Wed Oct 04, 2006 8:40 am

Post by kakapeepee »

well yeah i know, actually this is a part of my code

Code: Select all

global $_ENV, $_SERVER, $_POST;
echo "<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<form name=\"decision\" method=\"post\" action=\"http://127.0.0.1/web/file.php\">
<input type=\"hidden\" name=\"action\" value=\"add\">
<input name=\"name\" type=\"text\">
<input name=\"lname\" type=\"text\">
<br />
<label title=\"choice\" >
yes <input name=\"choice\" type=\"radio\" value=\"yes\">
No <input name=\"choice\" type=\"radio\" value=\"yes\"></label>

<input type=\"submit\" value=\"submit\" />
</form>

".read()."
</body>
</html>";

	if($_POST['action'] == "add")
	{
		
			$query = mysql_query("insert into m_record (name,lname,date,ip) values('$name','value2','value3','value4')");
		
	
}
im getting Undefined index: action

this is still under coding, but i stopped on that stage as u see, i wanna load that function submit() only when i click submit, for that reason i have created a hidden input called ACTION but it is sayin undefined :S
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Code: Select all

if(isset($_POST['action']) && $_POST['action'] == "add")
 $query = mysql_query("insert into m_record (name,lname,date,ip) values('$name','value2','value3','value4')");
you need isset to check if the form was submitted or not. and if you just define the function, its no real good until its called, hence I discarded the function.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

also, you don't need to declare $_ENV, $_SERVER and $_POST global... they already are... in fact, they're Superglobals
kakapeepee
Forum Newbie
Posts: 14
Joined: Wed Oct 04, 2006 8:40 am

Post by kakapeepee »

thank you guys !! it is working


one more question

i have added the following below the query

Code: Select all

if(!$query)
			{
				$result =  "An error has occured";
			}
			else
			{
				$result = "Thanks...";
			}
but is is giving me Undifined variable:$result

why ?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Since the variable $query is defined within an if(), perhaps it is not being defined. A good practice is to initialize all variables.
(#10850)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

arborint wrote:Since the variable $query is defined within an if()
It's not defined there, it's used - probably without declaration.
Does the warning message say $result or $query?
Please copy&paste the warning and mark the line of code mentioned in the warning.
kakapeepee
Forum Newbie
Posts: 14
Joined: Wed Oct 04, 2006 8:40 am

Post by kakapeepee »

Notice: Undefined variable: result in d:\web\file.php on line 27

line 27 has the $result used in the echo that displays that parse the html codes
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

May we see the first 27 lines of the script as it is right now?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

kakapeepee wrote:line 27 has the $result used in the echo that displays that parse the html codes
Right, but where is it set?
(#10850)
Post Reply