I am making a register page and I have one error.

if ($_POST['submit'])

I keep getting Notice: Undefined index: submit in C:\xampp\htdocs\globallypictured\register.php on line 6

NO IDEA WHY. . . Can someone please help...

Dani AI

Generated

Short clarification and a safer approach.

That "Undefined index: submit" notice happens because the script reads a POST key that doesn't exist when the page is requested without form data. As pointed out, it is a notice (not a fatal error). As suggested, the underlying issue is usually a mismatch between what the form sends and what the script expects — or the page being loaded via GET before any POST happens. temporarily hid the message, but hiding notices is not the best long‑term fix.

A practical pattern is to detect the request method first and only then read and validate inputs. This avoids touching missing array keys and gives a clear place to run validation and sanitization:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
    $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
    // perform validation, hashing, DB insert, etc.
}

Quick troubleshooting checklist:

  • Confirm the HTML form uses method="post" and that input controls you expect actually have matching name attributes.
  • If using JavaScript/AJAX, verify the POST payload contains the fields and that Content-Type is correct.
  • Log notices during development so you can fix missing fields; in production log errors instead of displaying them to users.

Further reading:

Recommended Answers

All 5 Replies

That's not an error, it's a notice. You can turn off displaying them by calling error_reporting(0); , for example. This notice means, that $_POST does not contain anything for the index 'submit'. Don't worry about it.

Check the name of your submit button it should match what you put inside the $_POST[] array. I would guess that you capitalized the name on the button or forgot it completely.

Nope, that doesn't need to be: if the page is called without POST, you will always get that notice.

The poster was creating a registration page and given the level of the question the most likely scenario is that there is a naming mismatch. Since the poster did not mention they were using AJAX it is highy unlikely that he is passing POST variables any other way.

By setting error_reporting(0); you are just masking the problem. If you are really interested in passing POST variables by some other method it would be best to test the POST array with the isset() function. This way the user has knowledge that the data is not coming from a form and can either allow or reject the request based upon that knowledge. Setting the error reporting off just opens the site to XSS attacks.

Never assume always test.

Oh Okay i put that error_reporting(0); and that fixed the problem. Thanks guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.