jeffrydell Posted August 15, 2007 Share Posted August 15, 2007 Not quite sure how I'm getting THIS warning message: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in E:\...\script.php on line 796 From THIS code: $sql = @mysql_query("SELECT `owner_id` FROM `owners` WHERE `email` = '" . $Owner['email'] . "' AND `zipcode` = '" . $Owner['zipcode'] . "'"); if (mysql_num_rows($sql) > 0) { $row = mysql_fetch_assoc('$sql'); $Owner['owner_id'] = $row['owner_id']; } In order to 'get in' the IF, doesn't there have to be at least one row matching the query string? And if there IS one row, how can I get a message saying it's not a valid resource? Thanks for whatever help you can offer! Quote Link to comment https://forums.phpfreaks.com/topic/65136-solved-mysql_num_rowssql-0-but-also-not-a-valid-resource/ Share on other sites More sharing options...
lemmin Posted August 15, 2007 Share Posted August 15, 2007 That does seem strange. Put an or die(mysql_error()); at the end of your query to see what the problem is. $sql = @mysql_query("SELECT `owner_id` FROM `owners` WHERE `email` = '" . $Owner['email'] . "' AND `zipcode` = '" . $Owner['zipcode'] . "'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/65136-solved-mysql_num_rowssql-0-but-also-not-a-valid-resource/#findComment-325110 Share on other sites More sharing options...
BlueSkyIS Posted August 15, 2007 Share Posted August 15, 2007 remove the single quotes from $row = so you have... $row = mysql_fetch_assoc($sql); Quote Link to comment https://forums.phpfreaks.com/topic/65136-solved-mysql_num_rowssql-0-but-also-not-a-valid-resource/#findComment-325147 Share on other sites More sharing options...
Daniel0 Posted August 15, 2007 Share Posted August 15, 2007 To elaborate on what BlueSkyIS said, variables in a string are only parsed when enclosed with double quotes (same goes for control characters like \n or \t). Also, in this case (since you don't need any other data), you'd just pass the variable directly instead of putting it in a string. Quote Link to comment https://forums.phpfreaks.com/topic/65136-solved-mysql_num_rowssql-0-but-also-not-a-valid-resource/#findComment-325153 Share on other sites More sharing options...
jeffrydell Posted August 15, 2007 Author Share Posted August 15, 2007 Thanks - removing the quotes did it. I don't know how many times I've set up that type of scenario and never put those quotes in before ... guess it goes with being human. Here's a similar issue ... the array element $Dog['dog_id'] is null - I know, I tested for that: if ($Dog['dog_id'] !== "") { $sql = mysql_query("SELECT * FROM `dogs` WHERE `dog_id` = " . $Dog['dog_id']) or die(mysql_error()); $row = mysql_fetch_array($sql); // Line 838 $Dog['breed'] = $row['breed']; $Dog['sex'] = $row['sex']; $Dog['birthdate'] = dateconvert($row['birthdate'], 2); } ... as you can see, I already tried the "or die()" method of troubleshooting and got: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 (MySQL's usual 'ever so helpful' error messaging.) Prior to that, the error message from php was: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\...\script.php on line 838 ... which indicates to me that the IF() evaluated true, even though it SHOULD have been false because of !==""; Anyone???? Quote Link to comment https://forums.phpfreaks.com/topic/65136-solved-mysql_num_rowssql-0-but-also-not-a-valid-resource/#findComment-325221 Share on other sites More sharing options...
Daniel0 Posted August 16, 2007 Share Posted August 16, 2007 No, it evaluates to true and that is correct. The === (and !==) operator means identical. $Dog['dog_id'] is null and not "" (a empty string). You should use !empty($Dog['dog_id']) or just use != instead. Quote Link to comment https://forums.phpfreaks.com/topic/65136-solved-mysql_num_rowssql-0-but-also-not-a-valid-resource/#findComment-325445 Share on other sites More sharing options...
jeffrydell Posted August 16, 2007 Author Share Posted August 16, 2007 Thank you Daniel0! Most helpful. Quote Link to comment https://forums.phpfreaks.com/topic/65136-solved-mysql_num_rowssql-0-but-also-not-a-valid-resource/#findComment-325615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.