-1

I keep getting "Notice: Undefined index: username" when running this code.

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";
    }
}

here is the 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);
}
Ayden F
  • 3
  • 2

2 Answers2

4

Update Code

First check $_GET is !empty function in 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']) : '';
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40
-1

you are not sending username,password and hwid in url thats why it showing error only for thos not for action and invite_code. May be you are creating wrong url or you have empty value for username,password and hwid in url

Paritosh Mahale
  • 1,238
  • 2
  • 14
  • 42
  • I think because Aman gave a more direct answer, I can't downvote so it was the community. – Ayden F Oct 06 '17 at 06:02
  • i am not sure but if you see in comment $_GET contains Array ( [action] => login3 [invite_code] => 1 ) if he is creating wrong( without username and password value) url then system always get empty values. he need to thing about that – Paritosh Mahale Oct 06 '17 at 06:08