简体   繁体   English

mysql_num_rows错误

[英]mysql_num_rows error

I have problem with mysql_num_rows() function. 我对mysql_num_rows()函数有疑问。 I've checked query (it has proper syntax and I'm getting the result in sql) and connection to database and everything seems to be able to work. 我检查了查询(它具有正确的语法,并且在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');
}

I got this result: 我得到了这个结果:

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.

尝试使用mysqli_num_rows而不是mysql_num_rows

That's because $result is only known inside the first if-statement. 这是因为$ result仅在第一个if语句内是已知的。 You need to break it out and make it "globally" accessable. 您需要对其进行分解,并使其可以“全局”访问。

Also, if the $result fails, you will get that error, so you need to nest your sub-ifs inside if(!$row =.... 另外,如果$ result失败,则会收到该错误,因此您需要将子if(!$row =....嵌套在if(!$row =....

What does mysql_error(); mysql_error()是什么? say? 说? What does var_dump(); var_dump()是什么? say when you check $result? 说什么当您检查$ result? var_dump($result); var_dump($ result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM