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

Notice: Undefined index: username

当 运行 这段代码时,我一直收到 "Notice: Undefined index: username"。

Notice: Undefined index: username in /public_html/handler.php on line 7

Notice: Undefined index: password in /public_html/handler.php on line 8

Notice: Undefined index: hwid in /public_html/handler.php on line 9

<?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);
}

更新代码

首先检查$_GET!empty函数在php

$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']) : '';

您没有在 url 中发送用户名、密码和 hwid,这就是为什么它只显示那些不用于操作和 invite_code 的错误。 可能是您创建了错误的 url 或者您在 url

中的用户名、密码和 hwid 的值为空