我收到此错误
Notice: Undefined index: username in C:\xampp\htdocs\login.php on line 24
Notice: Undefined index: password in C:\xampp\htdocs\login.php on line 25
关于此代码
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect("localhost","root","") or die ("couldn't connect");
mysql_select_db("test") or die ("couldn't find DB");
$query = mysql_query("select * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if($numrows!=0)
{
//login goahead
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
if($username==$dbusername&&$password==$dbpassword)
{
echo "You're in! <a href='member.php'>click here to continue</a>";
$_SESSION['username']=$username;
}
else
echo"Incorrect Password";
}
}
else
die("That user does not exist!");
}
else
die("please enter a username and password");
?>
我已经尝试改变检查DB用户名并传递它的if语句,并尝试重新定义调用,但它不起作用。任何帮助都会很棒。
答案 0 :(得分:1)
您的问题似乎在这里:
$dbusername = $row['username'];
$dbpassword = $row['password'];
您的SQL查询似乎表明它没有使用行索引用户名或密码返回任何结果。
即。 $ row ['username']不存在等。