1

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"> 
1
  • You have not shown us enough code. In particular, you haven't demonstrated your <form> tags. Perhaps you're using GET not POST. Commented Feb 26, 2011 at 16:35

2 Answers 2

8

You should check it like this:

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

to avoid getting notice.

Sign up to request clarification or add additional context in comments.

2 Comments

-1 If the field is in the right form, and the form method is POST, then the variable will be set even if it's empty. I agree that it's wise to use isset where you can, but this is not the OP's problem.
I agree, additionally you should perform !empty() check.
2

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); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.