错误:mysql_num_rows()需要参数1

时间:2014-04-15 09:54:37

标签: php mysql

尝试运行此代码时出错:

        $sql = "SELECT * FROM user WHERE username = '$uname' AND password = '$password'";
        $result=mysql_query($sql);
        $num_row=mysql_num_rows($sql);
        $row=mysql_fetch_array($result);

问题在于行$num_row=mysql_num_rows($sql);

错误消息是:

Warning: mysql_num_rows() expects parameter 1 to be resource, string given

3 个答案:

答案 0 :(得分:2)

$num_row=mysql_num_rows($sql);

应该是

$num_row=mysql_num_rows($result);

答案 1 :(得分:0)

试试这个:

查询执行后计算行数并获取记录。

$sql = "SELECT * FROM user WHERE username = '$uname' AND password = '$password'";
$result = mysql_query($sql);

$num_row=mysql_num_rows($result);
$row=mysql_fetch_array($result);

答案 2 :(得分:0)

尝试此查询

 $sql = "SELECT * FROM user WHERE username = '$uname' AND password = '$password'";
        $result=mysql_query($sql);

        $num_row=mysql_num_rows($result);

        $row=mysql_fetch_array($result);