gpt4 book ai didi

php - 未定义索引 : on login (php)

转载 作者:行者123 更新时间:2023-11-29 13:18:30 25 4
gpt4 key购买 nike

我收到此错误

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");

?>

我尝试更改检查数据库用户名并通过的 if 语句的位置,并尝试重新定义调用,但它不起作用。任何帮助都会很棒。

最佳答案

您的问题似乎在这里:

$dbusername = $row['username'];
$dbpassword = $row['password'];

您的 SQL 查询似乎表明它没有返回任何包含行索引用户名或密码的结果。

即。 $row['username'] 不存在等..

关于php - 未定义索引 : on login (php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21175765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com