nairarun88 Posted September 14, 2012 Share Posted September 14, 2012 Hello, i have been working on client site... looking for help from experts.... i got the warning error on the site... Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\registration\login.php on line 19 code is bellow... kindly help me where i have did any mistake.... <?php $username = $_POST ['username']; $password = $_POST ['password']; if ($username&&$password){ $connect = mysql_connect("localhost","root","") or die("Couldn't connect!"); mysql_select_db("phplogin") or die("Couldn't find db"); $query = mysql_query("SELECT * FROM users WHERE username='$username"); $numrows = mysql_num_rows($query); echo $numrows; } else die("Please enter a username and password"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268354-problem-in-php-coding-in-c/ Share on other sites More sharing options...
Psycho Posted September 14, 2012 Share Posted September 14, 2012 Your query is failing. You need to verify that the query passed before you try to use the results. I would advise always creating your queries as string variables. Then if there is an error you can echo the query to the page to verify the contents. If you had done that in this instance the error would have been obvious. In the query you had an opening single quote mark around the username, but no closing single quote mark. There were a lot of other potential problems $username = trim($_POST['username']); $password = trim($_POST['password']); if ($username!='' && $password!='') { $connect = mysql_connect("localhost","root","") or die("Couldn't connect!"); mysql_select_db("phplogin") or die("Couldn't find db"); $query = sprintf("SELECT * FROM users WHERE username='%s' AND password='%s'", mysql_real_escape_string($username), mysql_real_escape_string($password)); $result = mysql_query($query) or die(mysql_error()); if(!$result) { die("Query: $query<br>Error: " . mysql_error()); } else { $numrows = mysql_num_rows($query); echo $numrows; } } else { die("Please enter a username and password"); } Quote Link to comment https://forums.phpfreaks.com/topic/268354-problem-in-php-coding-in-c/#findComment-1377798 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.