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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.