I'm writing a class, but I stucked in a function. It requests the email address by username, but it's only returning null.
Code:
private function getUserEmail($username){
if($stmt = $this->_mysqli->prepare("SELECT email FROM users WHERE username='?'")){
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($email);
$stmt->fetch();
var_dump($email);
$stmt->close();
return $email;
}
}
nullfrom the ->fetch() call means that there's no data at all (or you've fetched all available data already): php.net/manual/en/mysqli-stmt.fetch.php. Do aecho $stmt->num_rows()right after the ->execute() call. If you get 0, then you've just got no data at all.