Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

undefined Variable error 2

Status
Not open for further replies.

sazebac

Technical User
Apr 16, 2003
117
US
Code:
<?
include 'db.inc';
$regionName = clean($regionName, 30);
$scriptName = &quot;5-9.php&quot;;

if (empty($regionName))
{
?>
<form action=&quot;<?=$scriptName;?>&quot; method = &quot;get&quot;>
<br> Enter a region to browse :
<input type=&quot;text&quot; name=&quot;regionName&quot; value=&quot;ALL&quot;>
(type all to see all regions)
<br>
<input type=&quot;submit&quot; value = &quot;show wines&quot;>
</form>
<br><a href=&quot;index.html&quot;>Home</a>
} // end if user data
[/code 5-9.php]

The error message is &quot;Notice: Undefined variable: regionName in C:\Program Files\Apache Group\Apache2\htdocs\TMP7ykttga2gs.php on line 12&quot;

Line 12 is actually line 3 in this case because I did not paste the entire code. The <form> loads okay. When I take out line 3 I do not get an error. The clean() function is defined in db.inc, which looks like this
[code=db.inc]
<?
$hostName = &quot;localhost&quot;;
$databaseName = &quot;wines&quot;;
$username = &quot;&quot;;
$password = &quot;&quot;;

function clean($input, $maxlength)
{
$input = substr($input, 0, $maxlength);
$input = EscapeShellCmd($input);
return ($input);
}

?>
[/code db.inc]

Two questions. 
One: I named the file 5-9.php, but the error message calls it TMP7ykttga2gs.php. Why?
Two: What could be causing this error message?
Help. Thanks.
 
1) It's just a temp file, that happens on certain errors. My guess is it has something to do with the fact your page could in theory get multiple hits so with certain types of code it needs to make its own file... someone else may have a more definitive answer.

2) What's causing the error is exactly what the error message is saying most likely. You haven't defined $regionName, instead you just called it, and it has neither a value nor a spot in memory even. Kind of like if I told you, oh sure just paste X into your code, that'll fix it. If you think you have assigned a value to regionname above in the code, odds are you misspelled it, or capitalized it differently (variables are case sensitive in PHP), if you don't think you assigned a value to it or otherwise initialized it, then do.

-Rob
 
What happened is the example code in the book is incomplete. The code comes from the book &quot;Web DB apps with php and mysql&quot; and I don't recommend it unless your a pro at php. The book just lays out the sample code but doesn't bother to explain that it will not work if run.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top