Login script not working, can't match username and password
<p>I've coded a simple login script, however, it won't match username and password retrieved from form with the database inputs.</p>

<p>Here is the code:</p>

<pre><code>&lt;?php

// Include database connection settings
include $_SERVER["DOCUMENT_ROOT"] . 'system/db/DbConnection.php';

// Inialize session
session_start();

// Retrieve POST variables from login form
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);

// Retrieve username and password from database according to user's input
$qLogin = mysql_query("SELECT * FROM users WHERE username = '{$username}'") or die("MySQL ERROR: ".mysql_error());
$rLogin = mysql_fetch_array($qLogin);
echo '1&lt;BR /&gt;';

echo $password . '&lt;BR /&gt;';
echo $rLogin['password'] . '&lt;BR /&gt;';
echo '2&lt;BR /&gt;';

echo $username . '&lt;BR /&gt;';
echo $rLogin['username'] .'&lt;BR /&gt;';
echo '3&lt;BR /&gt;';

// Check username and password match
if ($username == $rLogin['username'] &amp;&amp; $password == $rLogin['password']) {
    echo '4&lt;BR /&gt;';
    // If last_login and login_ip == "", its the users first time loging in
    if($rLogin['last_login'] == "" &amp;&amp; $rLogin['login_ip'] == ""){
    echo '5&lt;BR /&gt;';
    // The date right now
    $date = date("d/m/y H:i:s");
    // Get user IP
    $ip = $_SERVER['REMOTE_ADDR'];
    // Update last_login and login_ip
    echo '6&lt;BR /&gt;';
    mysql_query("UPDATE users SET last_login = '{$date}', login_ip = '{$ip}' WHERE username = '{$username}'") or die("MySQL ERROR: ".mysql_error());
    }

    // Set session variables
    $_SESSION['username'] = $username;
    $_SESSION['auth'] = $rLogin['auth'];

    //header("Location: ../success/");
    //exit();
    echo '7&lt;BR /&gt;';
} else {
    // Jump to login page
    //header("Location: ../");
    //exit();
    echo '8&lt;BR /&gt;';
}
?&gt;
</code></pre>

<p>I get the following echoed: 1,2,3 and 8. I also get the username and password that I've included an echo to, and they all match..</p>

<p>PS: No need to comment about unsecured passwords, the passwords are heavily encrypted, the passwords are equal when I echo them so that is not the problem either.</p>
