janey98
New Coder
Hello world!
Looking for help with my login system code (php and SQL).
This error is returning when I try to login on my form.
Fatal error: Call to a member function execute() on boolean in /home/****/****/***/auth.php on line 16
Just wondering if I am missing something, as I am fairly new to coding.
Thanks!
Looking for help with my login system code (php and SQL).
This error is returning when I try to login on my form.
Fatal error: Call to a member function execute() on boolean in /home/****/****/***/auth.php on line 16
PHP:
<?php
include 'dbconn.php';
if (isset($_POST['username']) && isset($_POST['password_hash']))
{
$username = $_POST['username'];
$password_hash = $_POST['password_hash'];
if (empty($username)) {
header("Location: login.html?error=Email is required");
}else if (empty($password_hash)){
header("Location: login.html?error=Password is required");
}else {
$stmt = $conn->prepare("SELECT * FROM users WHERE username=?");
$stmt->execute([$username]);
if ($stmt->rowCount() === 1) {
$user = $stmt->fetch();
$user_email = $user['username'];
$user_password = $user['password_hash'];
if ($username === $user_email) {
if (password_verify($password_hash, $user_password)) {
$_SESSION['user_email'] = $user_email;
$_SESSION['user_password'] = $user_password;
header("Location: index.php");
}else{
header("Location: login.html?error=Incorrect email or password=$email");
}
}else {
header("Location: login.php?error=Incorect User name or password&email=$email");
}
}else {
header("Location: login.php?error=Incorect User name or password&email=$email");
}
}
}
?>
Just wondering if I am missing something, as I am fairly new to coding.
Thanks!