Edward Posted March 6, 2007 Share Posted March 6, 2007 Please can someone tell me why I am getting this error message?? Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/viki3555/public_html/page_05_the_honeymoon_competition.php on line 132 It was working fine until I moved it to a different domain. I updated the username and passwords (removed from code below) which is all that needed changing, but it doesn't work. It also says a match is found (ie $row_count doesn't equal zero) but that is incorrect. Urgent help would be great! $mysql_errors = ''; if ($db_connect = @mysql_connect('localhost', 'username', 'password')) { if (!@mysql_select_db('database')) { $mysql_errors .= '<li>Could not select the database because <b>' . mysql_error() . '</b>.</li>'; } } else { $mysql_errors .= '<li>Could not connect to MySQL because: <b>' . mysql_error() . '</b>.</li>'; } if ($mysql_errors) { echo '<div class="errors">'; echo 'Sorry, the following errors were encountered:'; echo '<p>' . $mysql_errors . '</p>'; echo '</div>'; } else { # If there are no MySQL errors # Check that the voter hasn't already voted $sql = "SELECT * FROM mike_and_viki_the_honeymoon_voters WHERE entrant_name = '$entrant_name';"; echo "<p>$sql</p>"; $result = mysql_query($sql); $row_count = mysql_num_rows($result); if ($row_count != '0') { echo '<div class="errors">'; echo 'Sorry, the following errors were encountered:'; echo "<li>$entrant_name, you cannot enter more than once, that's cheating!</li>"; echo '</div>'; form(); } else { $query = "INSERT INTO mike_and_viki_the_honeymoon_voters VALUES ('', '" . $entrant_name . "','" . $entrant_answer . "')"; if ($result = mysql_query($query)) { # Get the existing count total for that location and increase it by 1 $sql = "SELECT * FROM mike_and_viki_the_honeymoon_votes WHERE entrant_answer = '$entrant_answer';"; $result = mysql_query($sql); $row_count = mysql_num_rows($result); if ($row_count == '0') { $query = "INSERT INTO mike_and_viki_the_honeymoon_votes VALUES ('" . $entrant_answer . "','1')"; if ($result = mysql_query($query)) { echo "<p>Thank you $entrant_name, your entry has been recorded.</p>"; } else { echo "<p class=\"errors\">Sorry $entrant_name, unfortunately your vote could not be sent to the database. Please try again later.</p>"; } } else { while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $new_answer_count = $row['answer_count'] + 1; } # end of while loop $query = "UPDATE mike_and_viki_the_honeymoon_votes SET answer_count = '" . $new_answer_count . "' WHERE entrant_answer = '$entrant_answer' LIMIT 1"; if ($result = mysql_query($query)) { echo "<p>Thank you $entrant_name, your entry has been recorded.</p>"; } else { echo "<p class=\"errors\">Sorry $entrant_name, unfortunately your vote could not be sent to the database. Please try again later.</p>"; } } } else { echo "<p class=\"errors\">Sorry $entrant_name, unfortunately your vote could not be sent to the database. Please try again later.</p>"; } } # End of: if ($row_count != '0') } # End of: if ($mysql_errors) Link to comment https://forums.phpfreaks.com/topic/41534-mysql_num_rows-error-not-sure-why/ Share on other sites More sharing options...
fert Posted March 6, 2007 Share Posted March 6, 2007 change $result = mysql_query($sql); to $result = mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/41534-mysql_num_rows-error-not-sure-why/#findComment-201250 Share on other sites More sharing options...
willpower Posted March 6, 2007 Share Posted March 6, 2007 you ahev an error in your $sql HERE entrant_answer = '$entrant_answer';"; should be HERE entrant_answer = '$entrant_answer'"; Link to comment https://forums.phpfreaks.com/topic/41534-mysql_num_rows-error-not-sure-why/#findComment-201253 Share on other sites More sharing options...
Edward Posted March 6, 2007 Author Share Posted March 6, 2007 Sweet! Thanks Fert. It said the table didn't exist, I'd put a space at the start of the table name when setting up the database in phpMyAdmin, D'ohhhhhhhhhhhhhhhhhhhhhhh!! Link to comment https://forums.phpfreaks.com/topic/41534-mysql_num_rows-error-not-sure-why/#findComment-201262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.