-1

我在登录 php 时遇到问题。是说注意:未定义的索引:登录..我尝试自己修复它,但它变得最糟糕T_T请帮助我

这是有错误的行

>$user = $_SESSION['log']['username'];

这是整个代码>

<?php
include("session/DBConnection.php");

$user = $_SESSION['log']['username'];
            $query = mysql_query("SELECT * FROM members WHERE username = '$user'") or die (mysql_error()); 
            $display = mysql_fetch_array($query);   ?>
4

2 回答 2

1

将其更改为:

if(isset($_SESSION['log']['username'])) { // add this IF statement to check the variable is set or not
   $user = $_SESSION['log']['username'];
   $query = mysql_query("SELECT * FROM members WHERE username = '$user'") or die (mysql_error()); 
   $display = mysql_fetch_array($query);
}
于 2013-06-24T04:05:21.717 回答
1

可能是因为$_SESSION['log']['username'];是空的。

添加用于测试它的行,例如:

if(!empty($_SESSION['log']['username']))
    {
     //your sql query
     ....

    }
于 2013-06-24T04:05:55.167 回答