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

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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

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.