Jump to content

mysql_num_rows() expects parameter 1 to be resource,


VikiC

Recommended Posts

Hi

 

I'm having a bit of bother with my login.  I created a login using this tutorial  http://www.phpeasystep.com/phptu/6.html and it works perfectly. 

 

So i have attempted to change it to meet my own database. So basically i've changed the database, table names etc to meet my own. I haven't changed any other lines. When i run it i get an error message:

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\checklogin.php on line 26

 

The code is below:

 

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="final year project"; // Database name
$tbl_name="tbl_user"; // 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");

// username and password sent from form
$mem_username=$_POST['mem_username'];
$mem_password=$_POST['mem_password'];

// To protect MySQL injection (more detail about MySQL injection)
$mem_username = stripslashes($mem_username);
$mem_password = stripslashes($mem_password);
$mem_username = mysql_real_escape_string($mem_username);
$mem_password = mysql_real_escape_string($mem_password);

$sql="SELECT * FROM $tbl_name WHERE username='$mem_username' and password='$mem_password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $mem_username and $mem_password, table row must be 1 row

if($count==1){
// Register $mem_username, $mem_password and redirect to file "login_success.php"
session_register("mem_username");
session_register("mem_password");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

 

Line 26 is $count=mysql_num_rows($result);

 

 

I'm baffled as to why the test database worked. I tried another test database but got the same error. baffled.com

 

Hope someone can help :)

 

MOD EDIT:

 . . . 

tags added.

Link to comment
Share on other sites

I now get:

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\checklogin.php on line 26

 

Fatal error: SQL: SELECT * FROM tbl_user WHERE username='' and password='', Error: Unknown column 'username' in 'where clause' in C:\xampp\htdocs\checklogin.php on line 26

Link to comment
Share on other sites

breakin' it down....

 

Fatal error: SQL: SELECT * FROM tbl_user WHERE username='' and password='', Error: Unknown column 'username' in 'where clause' in C:\xampp\htdocs\checklogin.php on line 26

 

SQL: SELECT * FROM tbl_user WHERE username='' and password=''

 

Error: Unknown column 'username' in 'where clause'

 

Unknown column 'username'

Link to comment
Share on other sites

Unfortunately, that tutorial sucks. It's outdated, uses deprecated functions, and makes the assumption that magic_quotes_gpc = On without even testing for it. It appears to be written for PHP 4. Forget most of what you learned from it, post your form here, and I'll have a look at what's happening.

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.