Jump to content

Why doesn't this work?! :\


SilverNova

Recommended Posts

Okay run this:
[code]<?php
session_start();

$conn = mysql_connect("localhost", "lov3dco_users", "test") or die('Unable to connect to MySQL');

// select what database to use
mysql_select_db("lov3dco_users", $conn) or die('Unable to select database - lov3dco_users');

// get the username from the form, as $username
$username = mysql_real_escape_string($_POST['username']);

// get the password from the form in md5
$password = md5($_POST['password']);

$recieve = "SELECT * FROM users WHERE username='$username' AND `password`='$password'";
$query = mysql_query($recieve, $conn) or die("Unable to peform query - " . mysql_error()); //do the query

if(mysql_num_rows($query) == '1')
{
    echo "login successful";
}
else
{
    echo "login failed";
}

echo "<br /><br /><b>DEBUG INFO:</b><br />
<code><b>Username</b>: {$username}<br />
<b>Password</b>: {$_POST['password']}<br />
<b>Password Hash</b>: {$password}<br />
<b>MD5 Hash of 'test'</b>: " . md5('test') . "<br />
<b>MD5 Hash TEST</b>: " . ((md5('test') == $password) ? 'passed' : 'failed') . "<br />
<b>Query</b>: {$recieve}<br />
</code>";

?>[/code]
This time it gives you some debug info.Post the debug info it produces here.
  • Replies 57
  • Created
  • Last Reply
[code]
login failed

DEBUG INFO:
Username: test
Password: tets
Password Hash: 45edd741812abf42a7b799a6fc558d9c
MD5 Hash of 'test': 098f6bcd4621d373cade4e832627b4f6
MD5 Hash TEST: failed
Query: SELECT * FROM users WHERE username='test' AND `password`='45edd741812abf42a7b799a6fc558d9c'
[/code]

TETS?! this means..?
Change this:
[code]if(mysql_num_rows($query) == '1')
{
    echo "login successful";
}
else
{
    echo "login failed";
}

echo "<br /><br /><b>DEBUG INFO:</b><br />
<code><b>Username</b>: {$username}<br />
<b>Password</b>: {$_POST['password']}<br />
<b>Password Hash</b>: {$password}<br />
<b>MD5 Hash of 'test'</b>: " . md5('test') . "<br />
<b>MD5 Hash TEST</b>: " . ((md5('test') == $password) ? 'passed' : 'failed') . "<br />
<b>Query</b>: {$recieve}<br />
</code>";[/code]
to this:
[code]if(mysql_num_rows($query) == '1')
{
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var

    header('Location: index.php');
}
else
{
    session_destroy();

    echo "login failed, please try again";
}[/code]

and you should be set to go, fingers crossed

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.