Voltiac
Voltiac

Reputation: 7

PHP can't find the submit button in my form. Undefined index

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

Upvotes: 0

Views: 496

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

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.

Upvotes: 1

Related Questions