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

-1 php sql undefined isset undefined-index

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

注意:未定义索引:第 7 行 /public_html/handler.php 中的用户名

注意:未定义索引:第 8 行 /public_html/handler.php 中的密码

注意:未定义索引:第 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";
    }
}
Run Code Online (Sandbox Code Playgroud)

这是 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);
}
Run Code Online (Sandbox Code Playgroud)

Ama*_*mar 5

更新代码

首先检查$_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']) : '';
Run Code Online (Sandbox Code Playgroud)