mysql_num_rows error

2019-01-20 15:35发布

I have problem with mysql_num_rows() function. 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.

// 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.

标签: php mysql mysqli
3条回答
叼着烟拽天下
2楼-- · 2019-01-20 16:11

That's because $result is only known inside the first if-statement. 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 =....

查看更多
forever°为你锁心
3楼-- · 2019-01-20 16:30

What does mysql_error(); say? What does var_dump(); say when you check $result? var_dump($result);

查看更多
爷的心禁止访问
4楼-- · 2019-01-20 16:33

try mysqli_num_rows instead of mysql_num_rows

查看更多
登录 后发表回答