mysql_num_rows返回零

时间:2015-01-01 15:48:44

标签: php mysql

<?php 
session_start();
$con=mysql_connect("localhost","root","samy");
mysql_select_db("project");
if($con)
{
    echo "Connected Successfully "; 
}
else
{
    echo "Error" . $sql . "<br>" . mysql_connect_error();
}
$name=$_SESSION['name'];
echo $name;
$sql1 = mysql_query("select cust_id from registered_user where name ='.$name.' ");
$r = mysql_num_rows($sql1);      
echo $r;
$row1 = mysql_fetch_array($sql1);
$cid = $row1['cust_id'];
echo $cid;
?>

由于num_rows返回零,因此$ cid也不会打印。 不知道错误是什么;

1 个答案:

答案 0 :(得分:1)

您应该删除dot(.)

$sql1 = mysql_query("select cust_id from registered_user where name ='$name'");
                                                                     ^     ^

还建议添加像这样的错误报告

$sql1 = mysql_query("select cust_id from registered_user where name ='$name'") 
        or die(mysql_error());