Sending Form Data with Button Value
You're facing an issue with submitting the value of submit buttons in a form post. In your provided code, the button names are labeled as "submit" instead of the intended product names, which prevents the PHP script from retrieving the desired value.
Solution:
To resolve this issue, you'll need to assign unique names to the submit buttons and ensure that the PHP script expects the value in the correct variable name. Here's an updated code snippet:
Sending Page:
<html> <form action="buy.php" method="post"> <select name="name"> <option>John</option> <option>Henry</option> <select> <input type="hidden" name="action" value="submit"> <input type="submit" name="submit" value="Tea"> <input type="submit" name="submit" value="Coffee"> </form> </html>
Receiving Page (buy.php):
<?php if (isset($_POST['action'])) { $name = $_POST['name']; $purchase = $_POST['submit']; // Database operations here } ?>
In this updated code:
By making these changes, you'll be able to successfully send the values of your submit buttons along with the other form data.
The above is the detailed content of How to Send Form Data with Button Values in PHP?. For more information, please follow other related articles on the PHP Chinese website!