I cant seem to figure out what to do here. I am trying to take a users username and password and compare it to hashed password in the db in order to validate their credentials and log them in.
Here is the code:
session_start(); // Start Session
include 'db.php';
$dbh = new PDO("mysql:host=$dbhost;dbname=$database_name", $dbusername, $dbpasswd);
// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
/*if((!$username) || (!$password)){
echo "Please enter ALL of the information! <br />";
include 'login.html';
exit();*/
//}
$sql = $dbh->prepare("SELECT * FROM users WHERE username=?");
$result = $sql->execute([$username]);
$users = $result->fetchAll();
// $sql = "SELECT * FROM users WHERE username = ?";
// $stmt = $dbh->prepare($sql);
// $result = $stmt->execute([$username]);
// $users = $result->fetchAll();
if (isset($users[0])) {
if (password_verify($password, $users[0]->password)) {
//Register some session variables!
session_register('email_address');
$_SESSION["username"] = $username;
$_SESSION["email_address"] = $email_address;
//session_register('special_user');
$_SESSION["user_level"] = $user_level;
mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");
header("Location: daily_picks.php");
} else {
echo "Invalid Credentials";
include 'login.html';
}
} else {
echo "Invalid Credentials";
include 'login.html';
}
Getting the error call to member function fetchAll() on a non-object in . . .