注意:未定义索引:用户名

时间:2013-12-01 18:49:38

标签: php

我的登录系统出现问题,我收到了这些错误:

Notice: Undefined index: username in C:\xampp\htdocs\Checkin\index.php on line 13
Notice: Undefined index: password in C:\xampp\htdocs\Checkin\index.php on line 14

线条是这样的:

    $db = new DB($db['host'], $db['gebruiker'], $db['wachtwoord'], $db['db']);
    $username = mysql_real_escape_string($_POST["username"]);
    $password = md5(md5($hotel["secret_salt"]) . md5($_POST["password"]));
    $find_sql = "SELECT look FROM users WHERE username = '{$username}' AND password = '{$password}'";
    $run_login = $db->query($find_sql);

那么,我能做什么,我希望有人知道像isset()一样的修复;或者空();

由于

韦斯利

2 个答案:

答案 0 :(得分:0)

是的,你是对的。您需要使用 isset 构造。这样做

<?php
    if(isset($_POST["username"]) && isset($_POST["password"]))
    {
    $db = new DB($db['host'], $db['gebruiker'], $db['wachtwoord'], $db['db']);
    $username = mysql_real_escape_string($_POST["username"]);
    $password = md5(md5($hotel["secret_salt"]) . md5($_POST["password"]));
    $find_sql = "SELECT look FROM users WHERE username = '{$username}' AND password = '{$password}'";
    $run_login = $db->query($find_sql);
    }
    else
    {
    echo "Username or Password was not passed";
    }

答案 1 :(得分:0)

if(isset($_POST['username']) && isset($_POST['password'])){
       $db = new DB($db['host'], $db['gebruiker'], $db['wachtwoord'], $db['db']);
       $username = mysql_real_escape_string($_POST["username"]);
       $password = md5(md5($hotel["secret_salt"]) . md5($_POST["password"]));
       $find_sql = "SELECT look FROM users WHERE username = '{$username}' AND password = '{$password}'";
       $run_login = $db->query($find_sql);

}