Undefined variable

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

Post Reply
alina_costin
Forum Newbie
Posts: 5
Joined: Fri Mar 05, 2004 1:02 am
Location: Romania
Contact:

Undefined variable

Post by alina_costin »

Hi all !
I am new in the world of PHP....and ask you to help me with a problem.
I have a page named view.php with this code :
********
HTML>
<?php
$db=mysql_connect("localhost","root","") ;
mysql_select_db("test",$db) ;
$result=mysql_query("select * from subcat where scatid=$scatid",$db) ;
while ($myrow=mysql_fetch_array($result))
{
echo "<br>First Name: ".$myrow["subcatid"] ;
echo "Last name: ".$myrow["sname"] ;
}
?>
</HTML>
******
In browser calling localhost\view.php?scatid=1 i get an error :

****
Note: Undefined variable : scatid in c:\inetpub\wwwroot\teste\view.php on line 5
****

my php is in c:\inetpub\wwwroot\teste .....

thank you very much
[mail_search][/mail_search]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you need to call in the variable like this

Code: Select all

HTML> 
<?php 

$scatid = $_GET['scatid'];

$db=mysql_connect("localhost","root","") ; 
mysql_select_db("test",$db) ; 
$result=mysql_query("select * from subcat where scatid=$scatid",$db) ; 
while ($myrow=mysql_fetch_array($result)) 
{ 
echo "<br>First Name: ".$myrow["subcatid"] ; 
echo "Last name: ".$myrow["sname"] ; 
} 
?> 
</HTML>
Rwad here for more info on this solution - http://uk2.php.net/variables.external

Mark
alina_costin
Forum Newbie
Posts: 5
Joined: Fri Mar 05, 2004 1:02 am
Location: Romania
Contact:

Post by alina_costin »

Thank you very much !
Post Reply