Forum Moderators: coopster

Message Too Old, No Replies

PHP 5 and Warning errors.

         

duckxtales

5:32 am on Dec 7, 2006 (gmt 0)

10+ Year Member




This error pops up after I upgraded to PHP 5:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/realpat/public_html/security/signupdemo.php on line 20
false

The code it is referencing:

$tempQuery = mysql_query("SELECT ID FROM security_images WHERE
referenceid='".$referenceid."' AND hiddentext='".$enteredvalue."'");

if (mysql_num_rows($tempQuery)!=0)
{
echo 'true';
} else {
echo 'false';
}

================================

What is wrong here? Is it compatibility issues? Or do I have to code a new way?

pixeltierra

6:33 am on Dec 7, 2006 (gmt 0)

10+ Year Member



sounds like the $tempQuery query failed, and it probably returned FALSE and not a resource.

I'd start by using the double quotes to interpolate the vars and dont concat:

$tempQuery = mysql_query("SELECT ID FROM security_images WHERE referenceid='$referenceid' AND hiddentext='$enteredvalue'");

Then I'd check for a valid resource before doing something with it: is_resource().

If there was an error you can see it with mysql_error().

Or maybe your query didn't find anything.

mcibor

9:50 am on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check this out

$sql = "SELECT ID FROM security_images WHERE
referenceid='".mysql_real_escape_string($referenceid)."' AND hiddentext='".mysql_real_escape_string($enteredvalue)."'";
$tempQuery = mysql_query($sql) or die(mysql_error());

if (mysql_num_rows($tempQuery)!=0)
{
echo 'true';
} else {
echo "false<br />SQL: $sql";
}

There should be any difference between concatenated and unconcatenated string

Michal