dongpin3794 2015-07-19 14:31
浏览 34
已采纳

会话未保存为id

basically I have been pulling my hair out over an unknown problem with my PHP code.

CODE(login_config.php):

    <?php   
session_start();                    //POST VARIABLES
                        $submit = $_POST['login_submit'];
                        $password = $_POST['login_password'];
                        $email = $_POST['login_email'];



if(isset($submit)){
   require 'password_config.php';
   require 'connect.php';

//PASSWORD VERIFYING
   $pass_query = "SELECT password FROM users WHERE email='$email'";
   $queried = mysql_query($pass_query);
   while($row = mysql_fetch_array($queried)){
   $user_pass = $row['password'];
   $veri_password = password_verify($password, $user_pass);
   }
   if($veri_password != true){$errors[] = '-Account does not exist ';}
   elseif($veri_password = true){

//CHECKING NUM ROWS
   $sql = "SELECT id, username FROM users WHERE email='$email'";
   $entered_user = mysql_query($sql);
   $num_rows = mysql_num_rows($entered_user);
   //STORING ID AS SESSION
   while($row1 = mysql_fetch_array($entered_user)){
   //PROBLEM IS HERE 
   $row1['id'] = $id;
   }

//ERRS ARRAY ESTABLISHED
   $errors = array();

//FURTHER VERIFYING
   if( empty($password) || empty($email) )
   {
   $errors[] = 'Please do not leave fields empty';
   }
   elseif( $num_rows != 1 )
   {
   $errors[] = '-Account does not exist ';
   }
   elseif( $num_rows == 1 )
   {
   $id = $_SESSION['key'];

      header('Location: profile.php');
      exit();
      }
   }

   }
?>

Question: Why is it that, when I get redirected to profile.php via header(), $_SESSION['key'] value is null? I have been using var_dump() to prove this. I want my session key to have a value of the user's id in my database and I see no problems with my code.

  • 写回答

3条回答 默认 最新

  • du1843 2015-07-19 14:42
    关注

    First of all $id variable is not defined anywhere.

    Doing $row1['id'] = $id; means assigning $id value to $row1['id'] If you want to store user id in $id then you should use

    $id = $row1['id'];
    

    The same bug with $id = $_SESSION['key']; This means assiging $_SESSION['key'] to $id. If you want to store $id value in a session:

    $_SESSION['key'] = $id;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)