Jump to content

simple login help


justAnoob

Recommended Posts

I use this same script for 4 other pages that I have. But for some reason, it will not work this time. When i register, it goes in the database just fine, the password is md5. Now when I go to log in, it keeps telling me that it is invalid username or password. I can take out the md5 on the reg and log script and it works fine. This doesn't make sense cause the same scripts work on other pages for me.

<?php
session_start();
include 'connection.php';

$check = mysql_real_escape_string($_POST["username"]);

$sql = "SELECT id FROM members WHERE username = '$check'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count > 0)
{

$_SESSION['dup'] = "This username is already registered.";
header("location: http://www.somewhere.com");
exit();
}
// if data is good, register the new member
else
{
$username = mysql_real_escape_string($_POST["username"]);
$password = md5($_POST["password"]);

$sql = "INSERT INTO members (username, password)VALUES('$username','$password')";

mysql_query($sql) or trigger_error();

unset($_SESSION['dup']);

header("location: http://www.somewhere.com");
exit();

}

mysql_close();
?>

<?php
session_start();
include 'connection.php';

$username = mysql_real_escape_string($_POST['username']);
$password = md5($_POST['password']);

$sql = "SELECT id FROM members WHERE username ='$username' and password = '$password' LIMIT 1";

$result=mysql_query($sql);
$count=mysql_num_rows($result);


if($count > 0)
{
$_SESSION['auth'] = "yes";
$_SESSION['who'] = "$username";
unset($_SESSION['message']);
$_SESSION['goodlog'] = 'Welcome ' . $username . "    <a href='http://www.somewhere.com/logout.php'>Log Out</a>" .' '; 

header("location: http://www.somewhere.com/index.php");
exit();                                                                     
}
else 
{
sleep(2);
$_SESSION['message'] = "Invalid User Id or Password.";
header("location: http://www.somewhere.com/index.php");
exit();
}
mysql_close();
?>

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.