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 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题