0

I really need help from you guys to fix my php task

Notice: Undefined index: username in C:\xampp\htdocs\wishal_login\register.php on line 6

Notice: Undefined index: password in C:\xampp\htdocs\wishal_login\register.php on line 7 {"success":0,"message":"Kolom username tidak boleh kosong"}

this is the code I made from register.php include_once "koneksi.php";

class usr{}

 $username = $_POST["username"];
 $password = $_POST["password"];
 $confirm_password = $_POST;

 if ((empty($username))) {
    $response = new usr();
    $response->success = 0;
    $response->message = "Kolom username tidak boleh kosong";
    die(json_encode($response));
 } else if ((empty($password))) {
    $response = new usr();
    $response->success = 0;
    $response->message = "Kolom password tidak boleh kosong";
    die(json_encode($response));
 } else if ((empty($confirm_password)) || $password != $confirm_password) {
    $response = new usr();
    $response->success = 0;

Please Help..

Morrison Chang
  • 11,691
  • 3
  • 41
  • 77
  • You probably need to check that your form has been submitted before you attempt to access the POST variables. – Nick Nov 09 '19 at 05:05

1 Answers1

0

The username & password values don’t exist on $_POST. Dupe of "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP.

Debug your client side, it is most likely not sending those fields. Or at least not sending them in the body of the message.

Cheers, Ethan

Ethan Melamed
  • 367
  • 1
  • 11
  • This should be a comment, not an answer. And, you can flag to close as a duplicate rather than linking to the dupe in a comment – Nick Nov 09 '19 at 05:06