Jump to content

Archived

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

SilverNova

Why doesn't this work?! :\

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.

Share this post


Link to post
Share on other sites
[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..?

Share this post


Link to post
Share on other sites
You are using the incorrect password. The password you want to use is test and not tets

The DEBUG is what I create with login scripts when they dont work etc. It just shows whats going on.

Share this post


Link to post
Share on other sites
Argh omw, was filling it in automatically for a while using FF... but now that it's resolved -

what script can i finally use?! :D

Many thanks for all your help - i'll be sure to link back to you from all my sites in future!!  ;D

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.