Nuv Posted April 12, 2011 Share Posted April 12, 2011 I am getting the following warning with the code below.Can someone please point me why the warning ? Warning Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/r.php on line 500 Code $sql = "SELECT * FROM funeral WHERE name='".$name."' AND phone='".$phone."'"; $result = mysql_query($sql); if((mysql_num_rows($result)) == 0) { $insertsql = "INSERT INTO funeral (name, street, city, shrtstate, state, pincode, phone) VALUES ('".$name."', '".$street."', '".$city."', '".$shrtstate."', '".$state."', '".$pincode."', '".$phone."')"; $insert = mysql_query($insertsql); } Quote Link to comment https://forums.phpfreaks.com/topic/233462-mysql_num_rows-warning/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2011 Share Posted April 12, 2011 If you search for that error message, you will find that it generally means that your query failed due to an error of some kind and you need to (always) have some error checking and error reporting logic in your code to get it to tell you why the query failed. For troubleshooting purposes, you can echo mysql_error() on the next line after the line with your mysql_query() statement to find out why the query is failing. Quote Link to comment https://forums.phpfreaks.com/topic/233462-mysql_num_rows-warning/#findComment-1200471 Share on other sites More sharing options...
Nuv Posted April 12, 2011 Author Share Posted April 12, 2011 Ah after doing that i realized that it won't its throwing errors where there is ' in between names, like HODGE'S FUNERAL CHAPEL. So the solution for it is to use " and i will have to escape it right ? Quote Link to comment https://forums.phpfreaks.com/topic/233462-mysql_num_rows-warning/#findComment-1200592 Share on other sites More sharing options...
Pikachu2000 Posted April 12, 2011 Share Posted April 12, 2011 All all data should be validated and sanitized. String type data should be escaped using mysql_real_escape_string before it is allowed into a query string. Quote Link to comment https://forums.phpfreaks.com/topic/233462-mysql_num_rows-warning/#findComment-1200594 Share on other sites More sharing options...
Nuv Posted April 12, 2011 Author Share Posted April 12, 2011 Oh yeah. I do that always except when i am the only one to use that script. Quote Link to comment https://forums.phpfreaks.com/topic/233462-mysql_num_rows-warning/#findComment-1200675 Share on other sites More sharing options...
Pikachu2000 Posted April 12, 2011 Share Posted April 12, 2011 As you now see, it doesn't really matter who uses the script. Quotes not only allow SQL injection, they can break query strings. Quote Link to comment https://forums.phpfreaks.com/topic/233462-mysql_num_rows-warning/#findComment-1200681 Share on other sites More sharing options...
Nuv Posted April 12, 2011 Author Share Posted April 12, 2011 Yeah Will always remember that. Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/233462-mysql_num_rows-warning/#findComment-1200689 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.