0

SOLVED!

Seems that I only had to add isset to my check.

 if(isset($_POST['submitBtn'])) { 

I am validating and processing some date that I want to get from my HTML form. I placed this form inside a $form variable, this way I can send people back to the register form. But somehow my PHP can't find my submit button ans gives me the error: undiefined index. Note that the PHP is in the same file as the form.

Because my form is rather long, I just post the submitbutton with the example:

 $form = "<form action='register.php' method='post'> <table> <tr> <td></td> <td><input type='submit' name='submitBtn' value='Register'></td> </tr> </table> </form>"; 

Part of my PHP:

 if($_POST['submitBtn']) { $firstname = strip_tags($_POST['firstname']); $lastname = strip_tags($_POST['lastname']); $username = strip_tags($_POST['username']); 
6
  • 1
    Try if(isset($_POST['submitBtn'])) and close your conditional } - you also need to echo $form; somewhere. Plus, Undefined index... what? - That's rather b-r-o-a-d. Commented Sep 26, 2014 at 16:14
  • Where are your firstname, lastname and username form inputs? Commented Sep 26, 2014 at 16:15
  • My form is rather long, I shortened it up a bit. they are present. Let me add the isset, didn't noticed that! Bit this was the solution already! After a few hours of coding, I just stared blind to all the code. Thanks a lot! Commented Sep 26, 2014 at 16:17
  • Want me to put that comment of mine as an answer? Tell me which part of it worked. Commented Sep 26, 2014 at 16:19
  • 1
    Well, answers are usually put in to close the question. Commented Sep 26, 2014 at 16:21

1 Answer 1

1

Putting in my comment as an answer, because that's how it's done on Stack in order to close a question and be marked as solved.

Instead of if($_POST['submitBtn']) you're not checking to see if it is set.

Do if(isset($_POST['submitBtn'])) instead.

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

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.