dongyin4202 2013-04-13 20:32
浏览 64

php登录:未定义索引[关闭]

Im very new to php and this is my first go on on this login. so when im typing in a valid username and password from the database im getting these two errors:

Notice: Undefined index: brukernavn on line 3

Notice: undefined index: passord on line 4

$username = $_POST['brukernavn'];
$password = $_POST['passord'];

if($username&&$password)
{

$connect = mysql_connect("localhost", "root", "") or die ("Cannot connect");
mysql_select_db("prosjekt") or die ("Cant find db");

$query = mysql_query("SELECT * FROM bruker WHERE brukernavn='$username'");

$radnum = mysql_num_rows($query);

if ($radnum!=0)
{

while ($rad = mysql_fetch_assoc($query))
{
    $dbuser = $rad['brukernavn'];
    $dbpass = $rad['passord'];
}

if ($username==$dbuser&&$password==$dbpass)
{
echo "Logged in";
}
else
    echo "Wrong username or password";

}
else
    die("That user does not exist!");


}
else
    die("Please enter a username and password!");




?>

Could anyone see where i went wrong here?

  • 写回答

2条回答 默认 最新

  • dshkmamau65777662 2013-04-13 20:34
    关注

    You're trying to access two variables that haven't been assigned yet:

    $username = $_POST['brukernavn'];
    $password = $_POST['passord'];
    

    You either:

    1. Need to wrap your login code in an if statement to check to see if the form has been submitted

    2. Need to check to see if those variables are set before accessing their values

    评论

报告相同问题?

悬赏问题

  • ¥15 关于Lammps建模的描述
  • ¥15 #lingo#请问一下为什么会出现以下情况,是因为l第一个值是0的缘故吗?
  • ¥15 设计格雷码同步八进制计数器
  • ¥100 改写matlab程序(关键词-系统对)
  • ¥15 函数信号发生器仿真电路
  • ¥15 Qt的pixmap和image图片加载都导致程序崩溃怎么办
  • ¥15 Kali木马生成问题求解
  • ¥30 求一下解题思路,完全不懂
  • ¥15 C51单片机串口控制JQ6500语音模块
  • ¥30 想给yolo5模型加一个图片识别界面,但是图片还没有检测出来就闪退了