给相同 name就可以了, 类似radio的和checkbox的用法:
You can give each input a different value and keep the same name:
<input type="submit" name="action" value="Submit" /> <input type="submit" name="action" value="Update" /> <input type="submit" name="action" value="Delete" />
php接收:
Then in the code check to see which was triggered:
if ($_POST['action'] == 'Submit') { //action for submit here } else if ($_POST['action'] == 'Update') { //action for update here } else if ($_POST['action'] == 'Delete') { //action for delete } else { //invalid action! }
The only problem with that is you tie your logic to the text within the input. You could also give each one a unique name and just check the $_POST for the existence of that input:
<input type="submit" name="update_button" value="Update" /> <input type="submit" name="delete_button" value="Delete" />
And in the code:
if (isset($_POST['update_button'])) { //update action } else if (isset($_POST['delete_button'])) { //delete action } else { //no button pressed }