我在登录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); ?>
答案 0 :(得分: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);
}
答案 1 :(得分:1)
可能是因为$_SESSION['log']['username'];
为空。
添加测试线,例如:
if(!empty($_SESSION['log']['username']))
{
//your sql query
....
}