Jump to content

Login script, comes up with user does not exsist when it does...


Recommended Posts

Hi guys is it possible someone can help me out please. ive been trying to work out whats wrong with this script for a few hours. and still havent got anywhere.

 

When i go to login in it, comes up with what its ment to if a user is not in the db, but it is.

 

<?php
require('function.php');
session_start();
connect();

$username = @$_POST['username'];
$password = @$_POST['password'];
$submit = @$_POST['submit'];
if(loggedin())
{
die("You are already logged in!");
}else{
if($submit)
{
if($username&&$password)
	{
    $rememberme = $_POST['rememberme'];
    $password = md5($password);
$loginquery = mysql_query("SELECT username FROM users WHERE username='$username'");
    $numrows = mysql_num_rows($loginquery);
    
    if($numrows)
    {
        while($row = mysql_fetch_assoc($loginquery))
        {
            $password1 = $row['password'];
            }
        if($password==$password1)
        {
            if($rememberme == "on"){
                setcookie("username",$username,time()+259200);
                header("location: index.php");
                }else if($remembeme == ""){
            $_SESSION['username']  = $username;
		header("location: index.php");
		die;
        }
        }else{
            echo "user does not exist";
        }
    }
	}else{
		echo "please fill out all of the fields";
	}
}
    }
?>

<html>
<link href="style/main.css" rel="stylesheet" type="text/css" />
<form action="login.php" method="POST">
<table>

<tr>
<td>
Username:
</td>
<td>
<input type="text" name="username" />
</td>
</tr>

<tr>
<td>
Password:
</td>
<td>
<input type="password" name="password" />
</td>
</tr>

<tr>
<td>
Remember Me:
</td>
<td>
<input type="checkbox" name="rememberme" />
</td>
</tr>

<tr>
<td>
<input type="submit" name="submit" value="submit" />
</td>
</tr>
</table>
</form>

</body>
</html>

 

Thanks in advance.

There are 2 things that I see as wrong with a quick glance, which may or may not be causing your problem.

 

1) you are looping through any users with the same username, but only check the password against the last one.

 

2) you have an inconstant spelling of $rememberme

The "user does not exist" message is output when if($password==$password1) is FALSE.

 

Your first step would be to get your indentation under control so that you can see that the logic is not what you think it is.

 

Your next step would be to troubleshoot why the entered password does not match what is in your database table. Echo both values and find out why they don't match.

 

 

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.