Jump to content

mysql_num_rows help.


HCProfessionals

Recommended Posts

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();\">";
			}

Link to comment
https://forums.phpfreaks.com/topic/232407-mysql_num_rows-help/
Share on other sites

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();\">";
}

Link to comment
https://forums.phpfreaks.com/topic/232407-mysql_num_rows-help/#findComment-1195526
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.