tags:

views:

74

answers:

3

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.
+3  A: 

try mysqli_num_rows instead of mysql_num_rows

william
+1  A: 

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

Filip Ekberg
I don't think that is the case with the scope of $result - even though I wish it was with PHP sometimes - it should be scoped for the whole function, despite being inside the if.
Meep3D
A: 

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

Marien