Welcome to WebmasterWorld Guest from 54.162.105.6
And I have a process.php.
How do I do...
if(buttton pressed == "Add")
Do this...
else if(buttton pressed == "Edit")
Do that...
else if(buttton pressed == "Remove")
Do that...
What would be the actually code there?
You need to do a couple of things to make this work. First, set up your forms, one each for Add, Edit and Remove.
The form action will be to self, so next thing is retrieve what you have posted when you submit the form.
Do that with the $_POST variable. Here's a look at one way to code this.
<?php
$Add = $_POST['Add'];
$Edit = $_POST['Edit'];
$Remove = $_POST['Remove'];
if ($Add)
{
// Add Something
exit;
}
if ($Edit)
{
// Edit Something
exit;
}
if ($Remove)
{
// Remove Something
exit;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type=hidden name="Add">
<input type="submit" value="Add"></form>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type=hidden name="Edit">
<input type="submit" value="Edit"></form>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="hidden" name="Remove">
<input type="submit" value="Remove"></form>
Good luck.
don't blame me if it breaks anything...
And the line in question: if (isset($_POST[submit]) && $_POST[submit] == "Add")
don't get confused about this warning. it's very good that your reporting settings are set to warning. the index of the array is a string, Paul in South Africa just forgot to quote them. use $_POST['submit'] instead of $_POST[submit] (i marked the difference in bold) and everything should be fine. you can compare this to grandpas' post, he is using the correct syntax, too.
i guess that paul in south africa has warning messages switched off, so he learned it's no problem to simply write array indexes as constants instead of strings. it's a common mistake.
<form ...>
<input type="submit" name="act_add" value="Add" />
<input type="submit" name="act_del" value="Del" />
<input type="submit" name="act_edit" value="Edit" />
</form>
to realize, which button was pressed is then quite easy. because it's all a submit-type input element, only the data of the pressed button is passed. you can then check a pressed button by checking the according $_POST[button name] array entry:
if (isset($_POST['act_add'])) {
//Add Button pressed
...
}
if (isset($_POST['act_del'])) {
//Del Button pressed
...
}
if (isset($_POST['act_edit'])) {
//Edit Button pressed
...
}
this will even work with more then one form element but it does not make sense to have the same form element multiple times in your html.