Jump to content

Recommended Posts

I have the following code set up on a login page for my website.  When users register, the username, id, password, etc. are going into the table perfectly, but for some reason this part of the code is sending logins to login-failed.php.  That leads me to believe it's coming from just this line: if(mysql_num_rows($result) == 1) {  ...but I can't figure out why!  Can anyone help me?  Or should I move this to the PHP forum?  Here's the code:

 

$qry="SELECT * FROM users WHERE username='$username' AND password='".md5($_POST['password'])."'";

$result=mysql_query($qry);

 

if($result) {

if(mysql_num_rows($result) == 1) {

session_regenerate_id();

$member = mysql_fetch_assoc($result);

$_SESSION['SESS_MEMBER_ID'] = $member['id'];

$_SESSION['SESS_USER_NAME'] = $member['username'];

                        $_SESSION['SESS_GENDER'] = $member['gender'];

                        $_SESSION['SESS_AGE'] = $member['age'];

session_write_close();

header("location: home.php");

exit();

}else {

header("location: login-failed.php");

exit();

}

}else {

die("Query failed");

}

 

 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/190760-login-failed-cant-figure-out-why/
Share on other sites

A) Take some responsibility for your code on your server with your database (we don't have access to these, so the only person here who can troubleshoot what is going on is you.)

B) Echo the value being tested in the logic to see what it is to find out why the conditional test is failing. What does echoing mysql_num_rows($result) show?

C) If mysql_num_rows($result) is zero, find out why. Echo $qry, then look directly in your database using your favorite database management program and check if there is a row that exactly matches the username and password value that is being put into the query.

D) Does $username and $_POST['password'] have the correct values in them (for all we know, they don't, either because your form is invalid and is not sending anything or your logic that is for example setting $username is causing it to be empty...)

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.