【问题标题】:Notice: Undefined index: username注意:未定义索引:用户名
【发布时间】:2018-03-17 20:29:59
【问题描述】:

运行此代码时,我不断收到“注意:未定义索引:用户名”。

注意:未定义索引:用户名在 /public_html/handler.php 上线 7

注意:未定义索引:密码在 /public_html/handler.php 上线 8

注意:未定义索引:第 9 行 /public_html/handler.php 中的 hwid

<?php

include('db.php');

$action = $_GET['action'];

$username = $con->real_escape_string($_GET['username']);
$password = $con->real_escape_string(md5(md5(md5($_GET['password']))));
$hwid = $con->real_escape_string($_GET['hwid']);
$invite_code = $con->real_escape_string($_GET['invite_code']);

$logged = false;

if(!$action)
{
    echo "Error";
}
else
{   
if($action == "register_admin_xd")
{
    if($query = $con->query("INSERT INTO users (username,password) VALUES 
('$username','$password')"))
    {
        echo "1";
    }
    else
    {
        echo "0";
    }
}

这里是 db.php

$host = "dbhostname";
$user = "dbusername";
$pass = "dbpassword";
$data = "database";

$con = new mysqli($host, $user, $pass, $data);

if($con->connect_errno)
{
printf("Connect failed: %s\n", $con->connect_error);
}

【问题讨论】:

标签: php sql undefined isset undefined-index


【解决方案1】:

更新代码

首先检查$_GET是php中的!empty函数

$username = !empty($_GET['username']) ? $con->real_escape_string($_GET['username']) : '';
$password = !empty($_GET['password']) ? $con->real_escape_string(md5(md5(md5($_GET['password'])))) : '';
$hwid = !empty($_GET['hwid']) ? $con->real_escape_string($_GET['hwid']) : '';
$invite_code = !empty($_GET['invite_code']) ? $con->real_escape_string($_GET['invite_code']) : '';

【讨论】:

    【解决方案2】:

    您没有在 url 中发送用户名、密码和 hwid,这就是为什么它只显示错误而不是操作和邀请代码的原因。 可能是您创建了错误的 url,或者您在 url 中有用户名、密码和 hwid 的空值

    【讨论】:

    • 我认为因为 Aman 给出了更直接的答案,所以我不能投反对票,所以是社区。​​span>
    • 我不确定,但如果您在评论中看到 $_GET 包含数组([action] => login3 [invite_code] => 1),如果他创建错误(没有用户名和密码值)url,那么系统总是得到空值。他需要解决这个问题
    猜你喜欢
    • 2016-05-25
    • 2015-12-01
    • 2013-11-27
    • 2015-06-02
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多