Jump to content

mysql_num_rows() Error


bravo14

Recommended Posts

Hi Guys

 

The insert query works but i get the following warning son the screen

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/sites/maypolejuniors.com/public_html/subscribe2.php on line 153

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/sites/maypolejuniors.com/public_html/subscribe2.php on line 158

The code is as follows

include_once ('includes/connect.php');
//assign form entries from subscription form to variables 
$email = $_POST["form_email"]; 
$name = $_POST["form_name"]; 
$status = $_POST["form_subscribe2"]; 
echo ("status " . $status); 
$result="$sql='SELECT *FROM `email_table` where `email`=$email";

if(mysql_num_rows($result)>0)
{
echo('The email address '.$email.' is already subscribed to the Maypole Juniors newsletter');
}
else
if(mysql_numrows($result)==0)
{
	$sql="INSERT INTO `email_table` (`name`,`email`) VALUES ('".$name."','".$email."')";
	if(!mysql_query($sql,$con))
	{
		die('Error: '.mysql_error());
	}
	else
		{
			echo($name.' who has '.$email.' as their email address has successfully subscribed to the Mayple Juniors newsletter');
		}
}
else
{
	$sql="DELETE FROM `email_table` WHERE email='".$email."'";
	if(!mysql_query($sql,$con))
	{
		die('Error: '.mysql_error());
	}
	else
		{
			echo($name.' who has '.$email.' as their email address has successfully unsubscribed from the Maypole Juniors newsletter');
		}
}

?>

Link to comment
Share on other sites

There is also no mysql_query() statement, so the query is never executed and $email is likely a string and would need to be enclosed in single-quotes.

 

Why are you using both mysql_num_rows() and mysql_numrows(). The latter is an older depreciated name and has been replaced with the former. Be consistent in your coding.

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.