bargainbob Posted January 31, 2012 Share Posted January 31, 2012 I'm trying to set up a password changing form for users on my website, but keep hitting an error around this part of the code... { $chpwdcheck = "SELECT password FROM table WHERE password='$cpword' AND ID='$ID'"; $chpwdres = mysql_query($chpwdcheck) or die("Current Password Checking Problem: " . mysql_error()); $chpwdcheckrow = mysql_num_rows($chpwdcheckres); if ($usernamecheckrow > 0) { mysql_query("UPDATE table SET password='$npword' WHERE ID='$UID'") or die("Password Updating Problem: " . mysql_error()); $message = "You have successfully updated your password. <a href='index.php'>Click here </a>to return to the home page."; } else { $message = "You incorrectly entered your current password. Please <a href='chpwd.php'> try again</a>."; I get the following error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in directory/etc on line 41 Any ideas anyone? Link to comment https://forums.phpfreaks.com/topic/256139-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/ Share on other sites More sharing options...
Maq Posted January 31, 2012 Share Posted January 31, 2012 Where is "$chpwdcheckres" being defined? The error you're getting is usually caused by invalid SQL syntax. Link to comment https://forums.phpfreaks.com/topic/256139-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1313073 Share on other sites More sharing options...
bargainbob Posted January 31, 2012 Author Share Posted January 31, 2012 Ah I see that now, should be the following: { $chpwdcheck = "SELECT password FROM table WHERE password='$cpword' AND ID='$ID'"; $chpwdres = mysql_query($chpwdcheck) or die("Current Password Checking Problem: " . mysql_error()); $chpwdcheckrow = mysql_num_rows($chpwdcheckres); if ($chpwdcheckrow > 0) { mysql_query("UPDATE table SET password='$npword' WHERE ID='$UID'") or die("Password Updating Problem: " . mysql_error()); $message = "You have successfully updated your password. <a href='index.php'>Click here </a>to return to the home page."; } else { $message = "You incorrectly entered your current password. Please <a href='chpwd.php'> try again</a>."; However, I still get the same error message. :/ Link to comment https://forums.phpfreaks.com/topic/256139-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1313076 Share on other sites More sharing options...
Maq Posted January 31, 2012 Share Posted January 31, 2012 Is your table really called 'table'? Don't use it, it's a reserved word: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html Link to comment https://forums.phpfreaks.com/topic/256139-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1313093 Share on other sites More sharing options...
bargainbob Posted January 31, 2012 Author Share Posted January 31, 2012 No it's users. Didn't know if it was easier to read as just table? { $chpwdcheck = "SELECT password FROM users WHERE password='$cpword' AND ID='$ID'"; $chpwdres = mysql_query($chpwdcheck) or die("Current Password Checking Problem: " . mysql_error()); $chpwdcheckrow = mysql_num_rows($chpwdcheckres); if ($chpwdcheckrow > 0) { mysql_query("UPDATE users SET password='$npword' WHERE ID='$UID'") or die("Password Updating Problem: " . mysql_error()); $message = "You have successfully updated your password. <a href='index.php'>Click here </a>to return to the home page."; } else { $message = "You incorrectly entered your current password. Please <a href='chpwd.php'> try again</a>."; Link to comment https://forums.phpfreaks.com/topic/256139-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1313097 Share on other sites More sharing options...
bargainbob Posted January 31, 2012 Author Share Posted January 31, 2012 I also forgot to mention that the correct message is also displayed underneath the SQL error. Link to comment https://forums.phpfreaks.com/topic/256139-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1313105 Share on other sites More sharing options...
Maq Posted January 31, 2012 Share Posted January 31, 2012 Again, where is "$chpwdcheckres" being defined? Link to comment https://forums.phpfreaks.com/topic/256139-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1313110 Share on other sites More sharing options...
bargainbob Posted January 31, 2012 Author Share Posted January 31, 2012 Ah I see it now! Sorry about the confusion! $chpwdres = mysql_query($chpwdcheck) or die("Current Password Checking Problem: " . mysql_error()); $chpwdcheckrow = mysql_num_rows($chpwdcheckres); Should in fact read: $chpwdcheckres = mysql_query($chpwdcheck) or die("Current Password Checking Problem: " . mysql_error()); $chpwdcheckrow = mysql_num_rows($chpwdcheckres); Thank you for your help! Link to comment https://forums.phpfreaks.com/topic/256139-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1313113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.