doucai7294 2015-01-04 21:12
浏览 56

为什么我不能设置会话变量?

I had already used this code 2 times, but now doesn't work and i don't know why. Below is the code from the file process_login.php. The code works fine, but when i get to admin.php can´t echo $_SESSION['USER'] and the same isn´t set. Thanks in advance.

<?php
    session_start(); 
    mysql_connect('localhost','root','root');   
    mysql_select_db('user_db'); 

    $user=$_POST['user']; 
    $password=$_POST['password'];

    $sql="SELECT * FROM users WHERE username='".$user."' AND password='".$password."'";     
    $res=mysql_query($sql); 

    if (mysql_num_rows($res)>0) 
    {           
        $row=mysql_fetch_array($res); 
        $_SESSION['USER']=$row['username']; 
        header("location: admin.php");                              
    }   
    else
    {   
        header("location: login.php");
    }   

?>
  • 写回答

1条回答 默认 最新

  • dpnhp20440 2015-01-04 22:03
    关注

    Using mysql_fetch_array will return an array with id numbers while mysql_fetch_assoc will return textual representation of the columns.

    //mysql_fetch_array()
    $myarray = array(
        [0] => "BILLYBOB"
    );
    
    //mysql_fetch_assoc()
    $myarray = array(
        ["USER"] => "BILLYBOB"
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!