I am trying to create a login script that collects the information a user posts and then creates a session if the user has provided the relevant information. Every time I try to login I get the error:
PHP Fatal error: Call to a member function bind_param() on boolean
I have provided my code below: require '../../../db-config.php'; require '../distributor-config.php';
$user_role = $_POST['user_role'];
$user_username = $_POST['user_username'];
$user_password = $_POST['user_password'];
$stmt = $conn->prepare("SELECT role, id, emailaddress, username, firstname, surname FROM users WHERE role = ?, username = ?, password = ?");
$stmt->bind_param("sss", $user_role, $user_username, $user_password);
$stmt->execute();
$stmt->bind_result($role, $id, $emailaddress, $username, $firstname, $surname);
while($stmt->fetch()) {
if($stmt == 1 && $user_role == 'Manager') {
session_start();
$_SESSION['userinfo']['role'] = $id;
$_SESSION['userinfo']['id'] = $id;
$_SESSION['userinfo']['emailaddress'] = $emailaddress;
$_SESSION['userinfo']['username'] = $username;
$_SESSION['userinfo']['firstname'] = $firstname;
$_SESSION['userinfo']['surname'] = $surname;
header('location: ../manager-index.php?page=login&status=success');
}
elseif($stmt == 1 && $user_role == 'User') {
session_start();
$_SESSION['userinfo']['role'] = $id;
$_SESSION['userinfo']['id'] = $id;
$_SESSION['userinfo']['emailaddress'] = $emailaddress;
$_SESSION['userinfo']['username'] = $username;
$_SESSION['userinfo']['firstname'] = $firstname;
$_SESSION['userinfo']['surname'] = $surname;
header('location: ../user-index.php?page=login&status=success');
}
else {
header('location: ../login.php?page=login&status=error');
}
}
$stmt->close();
$conn->close();