chicago Posted March 19, 2011 Share Posted March 19, 2011 Hi guys, I'm new to forums so hopefully someone can help me. I keep getting the following error: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Blog2\checklogin.php on line 27 My code is: // Define $blog_user_name and $blog_user_password $blog_user_name=$_POST['blog_user_name']; $blog_user_password=$_POST['blog_user_password']; // To protect MySQL injection (more detail about MySQL injection) $blog_user_name = stripslashes($blog_user_name); $blog_user_password = stripslashes($blog_user_password); $blog_user_name = mysql_real_escape_string($blog_user_name); $blog_user_password = mysql_real_escape_string($blog_user_password); $sql="SELECT * FROM $tbl_name WHERE username='$blog_user_name' and password='$blog_user_password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); //THIS IS LINE 27 // If result matched $blog_user_name and $blog_user_password, table row must be 1 row if($count==1){ // Register $blog_user_name, $blog_user_password and redirect to file "index.php" session_register("blog_user_name"); session_register("blog_user_password"); header("location:index.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); Please can someone help I have know idea what the problem could be. Thanks. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 19, 2011 Share Posted March 19, 2011 For starters, the tutorials on phpeasystep.com are obsolete and shouldn't be used. I don't see anywhere in the code where you connect to the DB server and select the database. Quote Link to comment Share on other sites More sharing options...
chicago Posted March 19, 2011 Author Share Posted March 19, 2011 This isn't all the code it connects to the database before this section of code <?php ob_start(); $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="database"; // Database name $tbl_name="blog_users"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); Is there any way to solve the problem? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 19, 2011 Share Posted March 19, 2011 You can find out why the query is failing by adding some error checking and error reporting logic to the code - $result=mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
chicago Posted March 20, 2011 Author Share Posted March 20, 2011 It said that the query was empty??? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 20, 2011 Share Posted March 20, 2011 That would mean that the $sql variable itself is empty. About the only way(s) that could occur with the code you posted is if you have some non-printing character as part of the $sql variable name so that php is not seeing the same code that you posted or the code you posted isn't the actual code that is producing the error. For possibility #1, delete and retype the whole $sql variable name in both places in that code. For possibility #2, make sure the line number where the error is being reported at is the actual code you are showing us. Quote Link to comment 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.