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
https://forums.phpfreaks.com/topic/189584-simple-login-help/
Share on other sites

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.