Page 1 of 1

Database communication using php,mysql

Posted: Tue Mar 10, 2009 8:48 am
by harishreddy
$query="select * from emp where ename='$ename' and empno='$empno'";
print "<br>".$query;
$result=mysql_query($query);
print "<br>".$result."<br>";

if($result)
{
$res=mysql_fetch_array($result);
print_r($res);
while($row=$res)
{
echo "<br>".$row['ename'];
}
}

in the above code while loop executed infinite times,can any body tell the reason for that

Re: Database communication using php,mysql

Posted: Tue Mar 10, 2009 9:35 am
by kaisellgren
Please use code tags.

The reason is that the statement, which you throw in the while loop, always equals to true. You probably want:

Code: Select all

$res=mysql_fetch_array($result);
while($res)
{
echo "<br>".$res['ename'];
$res=mysql_fetch_array($result);
}
And as for the security, your code is vulnerable to SQL injections.