$_SESSION['id'] is null


$_SESSION['id'] is null

我正在尝试在php脚本中更新密码,howerver $_SESSION['id']为空。这是通过var_dump功能显示的。因此我无法更新它

<?php
session_start();
require "../init.php";
ini_set('display_errors', 1);

if(isset($_POST['update'])){
    $password = $_POST['user_pass'];
    $passwordEncrypted = sha1($user_pass); 
    $confpassword = $_POST['confirm_pass'];
    $confPasswordEncrypted = sha1($confirmPass);  
    if($password !== $confpassword){
       echo "Passwords don't match!";
    }else{
        $select_query = "SELECT id FROM user_info";
        $run_select_query = mysqli_query($con,$select_query); 
        while ($row_post=mysqli_fetch_array($run_select_query)){
            $_SESSION['id'] = $row['id'];
            $user_id = $_SESSION['id'];
            var_dump($user_id);
        }
        $update_posts = "UPDATE user_info SET user_pass='$passwordEncrypted',confirm_pass ='$confPasswordEncrypted' WHERE id='$user_id'";  
        $run_update = mysqli_query($con,$update_posts); 
        echo "<script>alert('Post Has been Updated!')</script>";
    }
}
?>

有什么想法吗?谢谢。

您在为

变量赋值时使用了错误的变量$row session

while ($row_post=mysqli_fetch_array($run_select_query)){
    $_SESSION['id'] = $row_post['id'];
    $user_id = $_SESSION['id'];
    var_dump($user_id);
}