昨夜mysqliの学習を始めたばかりですが、現在、作成した関数に問題があります。関数はユーザーにログインする必要があります。ただし、本物のパスワードまたは作成されたパスワードを使用して既存のユーザー名を入力すると、ログインページがリロードされて。が表示されます$user_id。私は何が悪いのか途方に暮れています。私がmysqlを持っていたとき、私はこの問題を抱えていませんでした。
/** 
 * Returns FALSE, if no valid user found
 * Returns user_id of matching user with $username and $password
 */
function login ($mysqli, $username, $password) {
    // not required at all
    // $user_id = user_id_from_username($mysqli, $username);
    // initialize, in case we do not get a mysqli-statement
    $userID = FALSE;
    $password = md5($password);
    $stmt = $mysqli->prepare(
                     "SELECT `user_id`          "
                   . "  FROM `users`            "
                   . " WHERE ( `username` = ? ) "
                   . "   AND ( `password` = ? ) "
            );
    if ( $stmt ) {
        $stmt->bind_param('ss', $username, $password);  
        $stmt->execute();
        $stmt->bind_result($userID);
        if ( TRUE !== $stmt->fetch()) {
            $userID = FALSE;
        }
    }
    $stmt->close();
    return $userID; 
}
そして、これがログインページで関数loginを呼び出すときです。$mysqliデータベースへの接続を含む変数です。
// Now, needs to check against FALSE to work [changed by @SteAp]
//   var_dump( $login ); returns with int(1) 
//   and this is what I want, the integer 1
//Sends me to start.php but start.php does not recognize 
//the variable $_SESSION['user_id']
if ( FALSE === ($login = login($mysqli, $username, $password)) ) {  
  $errors[] = 'That username/password combination is incorrect';
} else {
  $_SESSION['user_id'] = $login;
  header('Location: start.php');
  exit();
}
if (empty($errors) === false) {
  echo '<div>'. output_errors($errors) . '</div>';
}