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
https://forums.phpfreaks.com/topic/164841-mysql_num_rows-error/
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
https://forums.phpfreaks.com/topic/164841-mysql_num_rows-error/#findComment-869224
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.