I have a simple mysql query checking the database table ‘all_users’ for an e-mail which was entered in a text field.
The e-mail is in a variable called $email.
In my test case, $email is something@yahoo.com and that e-mail exists in the database table.
When I do this:
$result=mysql_query("select * from all_users where email='$email' ") or die (mysql_error());
$row=mysql_fetch_array($result);
$num=mysql_num_rows($result);
$num is zero even though $row is found.
So when I do echo $row['email']; it correctly prints out ‘something@yahoo.com’ but when I do echo $num; it’s 0!
What am I doing wrong here? I’ve done this a thousand times but never had this issue.
From http://php.net/manual/en/function.mysql-fetch-array.php – Returns an array that corresponds to the fetched row and moves the internal data pointer ahead
So change the order, i.e. first use
mysql_num_rowsand only then domysql_fetch_array