$_SESSION['id'] 为空 [英] $_SESSION['id'] is null

查看:101
本文介绍了$_SESSION['id'] 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to update the password in a php script,howerver $_SESSION['id'] is null. This is shown via the var_dump function. Hence I can't update it

<?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>";
    }

}
?>

有什么想法吗?谢谢.

推荐答案

您在为 session 变量赋值时使用了错误的变量 $row.

You are using a wrong variable $row while assign value to session variable.

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

这篇关于$_SESSION['id'] 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆