1

I have 2 pages and there is a form in each page. the first form accepts user input and preview it on the second page (hidden form elements). on the second form the user clicks the submit button and it insert that data into mysql.

The problem, the second page insert data into mysql once I get to that page via the form POST method and I get empty fields in the database and the isset function for the form submit button not working.

First page (form):

<html>
    <body>    
        <form action="review.php" method="post">
            Name: <input type="text" name="name"><br>
            Age: <input type="text" name="age"><br>
            <input type="button" name="submit" value="submit">
        </form>    
    </body>
</html>

I get to the second page for review called review.php with this code:

<?php
if (isset($_POST['submit'])) {
    // Mysql insert statment
    echo "Form has been submitted";
}    
?>

<html>
    <body>    
        <form action="review.php" method="post">
            Name: <input type="hidden" name="name"><p><?php echo $_POST['name']; ?></p><br>
            Age: <input type="hidden" name="age"><p><?php echo $_POST['age']; ?></p><br>
           <input type="submit" name="submit">
        </form>    
    </body>
</html>

Once I click on the review button from the first form, it inserts that into mysql, so the isset function on the review.php is not working.

1
  • In first form, you should use name="submit". Commented Sep 7, 2013 at 8:56

4 Answers 4

1

Because you miss this line on the first file

<input type="submit" name="submit" value="Review">
Sign up to request clarification or add additional context in comments.

2 Comments

The problem is the isset function is working with the first file submit button and i want it to work with the second file button instead?
There should be no problem with the second file botton, because you already define that: <input type="submit" name="submit">
1
if (isset($_POST['submit'])) { //but there isn't any Html attribute with the name submit

It should be like this:

<input type="submit" name="submit"/>

Now you won't get empty values

1 Comment

Hi, the if (isset($_POST['submit'])) is for the second form submit button called 'submit'. I don't want the first form button to do the database insertion
0

Put the Below code in Your First page

<input type="submit" value="submit" name="submit" />

Comments

0

In first page

Use:

<input type="submit" name='submit' value='Submit'>

Instead of

<input type="review">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.