...

View Full Version : not recognising a variable?!



jarv
07-19-2008, 06:35 PM
I get an error message:

Notice: Undefined index: spubs in C:\Documents and Settings\John\Desktop\phptesting\xampplite\htdocs\mps_php\search_result1.php on line 7

search box form:


<div id="top"><div id="search"><form action="search_result1.php" method="post" name="search form"><input name="spubs" type="text" class="searchbox" />&nbsp;<input name="search" class="searchbutton" type="submit" value="search" /></form></div></div>

search results page line7:


$r_name = $_GET['spubs'];

Fou-Lu
07-19-2008, 06:46 PM
Hey Jarv,
You're form method is post, not get, so $_GET['spubs'] won't exist. Try the $_POST['spubs'] instead, and don't forget to handle the !isset for it too, there is nothing preventing a user from directly attaching to the page (just die the page if its not set for example)

p4plus2
07-19-2008, 08:45 PM
I get an error message:

Notice: Undefined index: spubs in C:\Documents and Settings\John\Desktop\phptesting\xampplite\htdocs\mps_php\search_result1.php on line 7

search box form:


<div id="top"><div id="search"><form action="search_result1.php" method="post" name="search form"><input name="spubs" type="text" class="searchbox" />&nbsp;<input name="search" class="searchbutton" type="submit" value="search" /></form></div></div>

search results page line7:


$r_name = $_GET['spubs'];


you need to change


<div id="top"><div id="search"><form action="search_result1.php" method="post" name="search form"><input name="spubs" type="text" class="searchbox" />&nbsp;<input name="search" class="searchbutton" type="submit" value="search" /></form></div></div>
to


<div id="top"><div id="search"><form action="search_result1.php" method="get" name="search form"><input name="spubs" type="text" class="searchbox" />&nbsp;<input name="search" class="searchbutton" type="submit" value="search" /></form></div></div>

OR(MEAN NOT BOTH!!)


$r_name = $_GET['spubs'];

to


$r_name = $_POST['spubs'];


BUT YOU SHOULD


if(!isset $_GET['spuds']{
exit();
}
$r_name = $_GET['spubs'];

(modify the get or post as needed from your choice of solution.

masterofollies
07-20-2008, 04:17 PM
Using a form post would be like this.

if (isset($_POST["search"]))
{
$spubs = $_POST["spubs"];

echo "You are searching for the word $spubs";

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum