Reputation: 61
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.
Upvotes: 1
Views: 3608
Reputation: 14523
In first page
Use:
<input type="submit" name='submit' value='Submit'>
Instead of
<input type="review">
Upvotes: 0
Reputation: 3622
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
Upvotes: 1
Reputation: 619
Put the Below code in Your First page
<input type="submit" value="submit" name="submit" />
Upvotes: 0
Reputation: 171
Because you miss this line on the first file
<input type="submit" name="submit" value="Review">
Upvotes: 1