Session_register("a");
Session_start();要写在每页的最上方

解决方案 »

  1.   

    $sql="select * from user where username='".$a['username']."'";
      

  2.   

    看错了,$a不是数组
    <?
    if(session_is_registered('a'))
    {
    $sql="select * from user where username='".$a."'";
      

  3.   

    在user_info.php中看看有没有a的值如果没有的话。
    有$_SESSION["a"]看看有没有值。
      

  4.   

    每次取得的用户id都是1,说明有SESSION变量$a.不过楼主是用session_register()注册的.建议楼主使用$_SESSION数组注册/销毁SESSION变量.在user_info.php中,$username并没有注册到SESSION前面的页面也没有注册,所以$username是空值.
      

  5.   

    而且user_info.php,也没有用session_start();
      

  6.   

    现在可以了,user.php代码如下:
    <?
    $a=$array[username];
    $dbh =  mysql_connect('localhost:3306','root','shilyshare520'); 
    mysql_select_db('xinlu',$dbh); 
    $sql="select id from user where username='".$logname."' and password='".$password."'";
    $res = mysql_query($sql, $dbh);
    $array=mysql_fetch_array($res);
    if($array[id])
    {Session_start();
    Session_register('a');
    $a=$array[id];
    //printf($a);
    ?>
    这个我已经调试过了,每次都可以取得对应用户的id。