Page 1 of 1

Undefined variable

Posted: Fri Mar 05, 2004 1:02 am
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]

Posted: Fri Mar 05, 2004 2:55 am
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

Posted: Sat Mar 06, 2004 3:31 am
by alina_costin
Thank you very much !