I have a login site where users login with their emails. Each is assigned an auto-increment user_id. I want to fetch the associated user_id from the database and store it in the session so that when they submit content, their user_id can be gotten from the session and submitted with the content. However, my "get_user_id" function is not working to look up the user id from their email address. I've tried using all sorts of mysqli commands from fetch_row, get_result, bind_result, and nothing will return the user_id.
function get_user_id($email) {
//$email = mysqli_real_escape_string($this->conn, $email);
$query = "SELECT id from users where email=?";
if ($stmt = $this->conn->prepare($query)){
$stmt->bind_param('s',$email);
if($result = $stmt->execute()){
$row=$result->fetch_row();
return $row['id'];
} else return "no ID returned.";
}
}
The error message I am getting now is:
Fatal error: Call to a member function fetch_row() on a non-object