简体   繁体   中英

“Undefined index” notice after submitting HTML form

So I have a sign up form, and there is some PHP at the top of the code. It gives me this error:

Notice: Undefined index: register in /home/content/04/7195304/html/index.php on line 20

This is line 20:

if ($_POST['register']) {

Here is the submit button:

<input type="submit" class="gobutton" value="Register" name="register"/>

Edit

So here's my form tags:

<form action="index.php" method="POST">

You should check it like this:

if ( isset($_POST['register']) ) {}

to avoid getting notice.

Is your form using method="GET" instead of method="POST"?

You can also add addition checks to make sure the index exists, like this:

if (isset($_POST['register'])) {
    // do stuff
}

You can also debug the form submission like this:

var_dump($_POST);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM