bravo14 Posted July 5, 2009 Share Posted July 5, 2009 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 More sharing options...
haku Posted July 5, 2009 Share Posted July 5, 2009 It means that $result doesn't hold anything from the database - probably because there was an error in your query. I'm thinking you need to add a space between * and FROM. Link to comment https://forums.phpfreaks.com/topic/164841-mysql_num_rows-error/#findComment-869192 Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2009 Share Posted July 5, 2009 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 More sharing options...
haku Posted July 5, 2009 Share Posted July 5, 2009 I agree with consistency, but are you sure it's deprecated? I thought it was just an alias. Link to comment https://forums.phpfreaks.com/topic/164841-mysql_num_rows-error/#findComment-869231 Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2009 Share Posted July 5, 2009 Note: For backward compatibility, the following deprecated alias may be used: mysql_numrows() Always check first. Link to comment https://forums.phpfreaks.com/topic/164841-mysql_num_rows-error/#findComment-869238 Share on other sites More sharing options...
haku Posted July 5, 2009 Share Posted July 5, 2009 Excuse me Mr. High and Mighty. I looked at the other page first: http://jp2.php.net/manual/en/function.msql-numrows.php Which didn't say anything about it being deprecated. Why do you always have to be so haughty? Are you this negative in real life as well? Link to comment https://forums.phpfreaks.com/topic/164841-mysql_num_rows-error/#findComment-869250 Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2009 Share Posted July 5, 2009 That link ain't even to the mysql function in question. msql_numrows may in fact just be an alias. mysql_numrows is depreciated and does not currently have a section in the documentation. Link to comment https://forums.phpfreaks.com/topic/164841-mysql_num_rows-error/#findComment-869263 Share on other sites More sharing options...
haku Posted July 6, 2009 Share Posted July 6, 2009 Sorry Mr. Haughty. I'll make sure to bow to your supreme godliness in the future. Link to comment https://forums.phpfreaks.com/topic/164841-mysql_num_rows-error/#findComment-869613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.