mysql_num_rows错误

时间:2009-08-14 09:34:10

标签: php mysql mysqli

我有mysql_num_rows()函数的问题。我检查了查询(它有正确的语法,我在sql中获得结果)和连接到数据库,一切似乎都可以工作。

// some code here, connecting to database and working query to db
$query = "SELECT ff_client.email FROM ff_order, ff_client WHERE ff_order.id = '$order_number' AND ff_order.client_id = ff_client.id AND ff_client.email = '$email'";
if (!$result = mysqli_query($db, $query))   {
    echo '<p>Query wasn\'t found.</p>';
    exit;
}
if (!$num = mysql_num_rows($result)) {   // < the problem
    echo 'error';
}
if ($num == 0) {
    echo '<p>Insert proper email address.</p>';
}
else
{
    $_SESSION['crazyfotoApp']['token'] = $order_number;
    $_SESSION['crazyfotoApp']['multiformat'] = 1;
    header('Location: http://www.my.page.pl/zamow-odbitki.php?u=1');
}

我得到了这个结果:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /mnt/sda3/www/www1.my.page.pl/recover.php on line 37
error
Insert proper email address.

3 个答案:

答案 0 :(得分:4)

尝试mysqli_num_rows而不是mysql_num_rows

答案 1 :(得分:1)

那是因为$ result只在第一个if语句中知道。您需要将其分解并使其“全局”可访问。

此外,如果$ result失败,您将收到该错误,因此您需要将子if-ifs嵌套在if(!$row =....

答案 2 :(得分:0)

mysql_error();说? 什么是var_dump();当你检查$ result时说的var_dump($结果);