Jump to content

mysql_num_rows() expects parameter 1 to be resource, boolean given


chicago

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.