Jump to content

Problem with PHP/mySQL login code


husslela03

Recommended Posts

Hello I have a login code below:

 

I keep receiving this error:

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

 

I can't figure out what is wrong, but it seems to be always hitting the else statement of saying wrong username or password.

 

<?php

$con=mysql_connect("localhost", "xxxx", "xxxxx") or die ("cannot connect");
mysql_select_db("my_sasi") or die ("cannot select database");

$user=$_POST['username'];
$pass=$_POST['password'];

$user_name=stripslashes($user);
$pass_code=stripslashes($pass);
$username=mysql_real_escape_string($user_name);
$password=mysql_real_escape_string($pass_code);

$sql="SELECT * FROM logins, users WHERE logins.loginID==users.loginID AND logins.Email_Address='$username' AND logins.password='$password'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
echo $count;



if($count==1)
{
  
  session_register("username");
  session_register("password");
  session_register("accessLevel");
  header("Location:login_success.php");
}

else
{
  echo 'Wrong Username or Password';
  
  
  
  

}

mysql_close($con);
?>

Link to comment
Share on other sites

what about this line:

 

logins.loginID==users.loginID

 

is there a loginID in logins that is equal to loginID in users?  and does it also have a username and password that match that of the username and password in the query?

 

Maybe I need to have a loop that goes through each of the rows in that table and looks for that username and password..

 

that's what the query does .. it queries the database table in question for a match as per the conditions in the query statement.  that is whjy every condition must be met.

 

the rest of your code seems fine (aside from register_session(), but that won't affect the query), so if you do get a match from the query, your IF statement (if ($count == 1)) will let you know the result (a match or no match by the respective output.

Link to comment
Share on other sites

You asked if the user table also has username and password.  It does not.

 

So should i just query the login table for the username and password..

but i also need to pull the accessLevel from the users table, because that directs to what page the member will be directed to, based on their access level.

 

 

Link to comment
Share on other sites

if you are positive everything in your query matches with what is in the database, and you aren't receiving any errors, then i got nothing else to say as the only thing stopping the script from working would be your query credentials not matching those in your tables.

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.