Page 1 of 3
?action=something
Posted: Wed Oct 04, 2006 9:49 am
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
Posted: Wed Oct 04, 2006 9:58 am
by volka
Posted: Wed Oct 04, 2006 10:36 am
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
Posted: Wed Oct 04, 2006 11:01 am
by n00b Saibot
do you know about
superglobals?
Posted: Wed Oct 04, 2006 11:06 am
by volka
Posted: Wed Oct 04, 2006 11:16 am
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']
Posted: Wed Oct 04, 2006 11:16 am
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
Posted: Wed Oct 04, 2006 11:25 am
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.
Posted: Wed Oct 04, 2006 11:28 am
by Luke
also, you don't need to declare $_ENV, $_SERVER and $_POST global... they already are... in fact, they're
Superglobals
Posted: Wed Oct 04, 2006 12:01 pm
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 ?
Posted: Wed Oct 04, 2006 12:49 pm
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.
Posted: Wed Oct 04, 2006 12:53 pm
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.
Posted: Wed Oct 04, 2006 1:00 pm
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
Posted: Wed Oct 04, 2006 1:04 pm
by volka
May we see the first 27 lines of the script as it is right now?
Posted: Wed Oct 04, 2006 1:05 pm
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?