HCProfessionals Posted April 1, 2011 Share Posted April 1, 2011 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource. if ($_POST['subscribe']) { $email_subscribe = $_POST['email']; if (mysql_num_rows(mysql_query("SELECT * FROM newsletter WHERE email=$email_subscribe"))) { mysql_query("UPDATE newsletter SET active=1 WHERE email=$email_subscribe") or die ('Error updating the database'); echo "Thank you for subscribing!"; echo "<meta http-equiv=\"refresh\" content=\"0;url=javascript:history.back();\">"; } else { mysql_query("INSERT INTO newsletter (`email`,`active`) VALUES ('$email_subscribe', '1')"); echo "Thank you for subscribing!"; echo "<meta http-equiv=\"refresh\" content=\"0;url=javascript:history.back();\">"; } } elseif ($_POST['unsubscribe'] != 0) { $email_unsubscribe = $_POST['email']; if (mysql_num_rows(mysql_query("SELECT * FROM newsletter WHERE email=$email_unsubscribe"))) { mysql_query("UPDATE newsletter SET active=0 WHERE email=$email_unsubscribe") or die ('Error updating the database'); echo "You have been unsubscribed."; echo "<meta http-equiv=\"refresh\" content=\"5;url=javascript:history.back();\">"; } else { echo "Email does not exist."; echo "<meta http-equiv=\"refresh\" content=\"5;url=javascript:history.back();\">"; } Quote Link to comment https://forums.phpfreaks.com/topic/232407-mysql_num_rows-help/ Share on other sites More sharing options...
litebearer Posted April 1, 2011 Share Posted April 1, 2011 Un-proofread; however, try... if ($_POST['subscribe']) { $email_subscribe = $_POST['email']; $query = "SELECT * FROM newsletter WHERE email = '$email_subscribe'"; $result = $mysql_query($query); $num_r = mysql_num_rows($result); if ($num_r>0) { $query2 = "UPDATE newsletter SET active=1 WHERE email='$email_subscribe'"; $result2 = mysql_query($query2) or die ('Error updating the database'); echo "Thank you for subscribing!"; echo "<meta http-equiv=\"refresh\" content=\"0;url=javascript:history.back();\">"; } else { $query3 = "INSERT INTO newsletter (email, active) VALUES ('$email_subscribe', '1')"; $result3 = mysql_query($query3); echo "Thank you for subscribing!"; echo "<meta http-equiv=\"refresh\" content=\"0;url=javascript:history.back();\">"; } } elseif ($_POST['unsubscribe'] != 0) { $email_unsubscribe = $_POST['email']; $query4 = "SELECT * FROM newsletter WHERE email = '$email_unsubscribe'"; $result4 = mysql_query($query4); $num_r2 = mysql_num_rows($result4); if ($num_r2>0) { $query5 = "UPDATE newsletter SET active=0 WHERE email='$email_unsubscribe'"; $result5 = mysql_query($query5) or die ('Error updating the database'); echo "You have been unsubscribed."; echo "<meta http-equiv=\"refresh\" content=\"5;url=javascript:history.back();\">"; } else { echo "Email does not exist."; echo "<meta http-equiv=\"refresh\" content=\"5;url=javascript:history.back();\">"; } Quote Link to comment https://forums.phpfreaks.com/topic/232407-mysql_num_rows-help/#findComment-1195526 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.