Login script

I’m creating a a login system for my website and up until now it was working fine. Below is the code for the page i am developing:

<?php $mysqli = new mysqli("localhost", "root", "root", "login") or die ("Couldn't connect to the server!"); error_reporting(0); if ($_POST['login']) { if ($_POST['username'] && $_POST['password']){ $username = $mysqli->real_escape_string($_POST['username']); $password = $mysqli->real_escape_string(hash("sha512", $_POST['password'])); $userQuery = $mysqli->query("SELECT * FROM 'users' WHERE 'Username'='$username'"); $user = $userQuery->fetch_array(MYSQLI_BOTH); if (empty($user)) { die("That username doesn't exist! Try making $username today! ← Back"); } if ($user['Password'] != $password) { die("Incorrect password! ← Back"); } $salt = hash("sha512", rand() . rand() . rand()); setcookie("c_user", hash("sha512", $username), time() +24 * 60 * 60, "/"); setcookie("c_salt", $salt, $time() +24 * 60 * 60, "/"); $userID = $user['ID']; $mysqli->query("UPDATE 'users' SET 'Salt'='$salt' WHERE 'ID'='$userID'"); die("You are now logged in as $username!"); } } echo " <div style='width: 80%; padding: 5px 15px 5px; border: 1px solid #e3e3e3; background-color: #fff; color: #000;'

Login


Username:
Password:

No account? Register!
"; ?>

The code which i need help on is this line if (empty($user)) {
die(“That username doesn’t exist! Try making $username today! ← Back”);
}

If i type in a random user name into the usernae field it should come up with an error message which is stated above, instead the page just refreshes and there is no change taking place or any error message showing up. I have tried this line too but its not working; if ($user == ‘0’))

Please help, thank you

DUPLICATE POST

http://www.phphelp.com/forum/general-php-help/login-system-24531/new/#new

Sponsor our Newsletter | Privacy Policy | Terms of Service