1

I am trying to use multiple buttons in which each perform a different action on a table. For example if you click the 'Add to Sold' button, any checkbox that is selected will have an action performed on it (their status is changed to sold). I have the action php ready to go... however I am unsure how to put it all together so I can have 1 table with 4 different buttons. For right now I am just trying to echo out a statement that will show me that it is working.

Here are the buttons:

 <form action="/includes/tester.php" method="POST">

     <button class="button2" type="submit" value="runlist" name="runlist"><i class="fa fa-calendar-plus-o" style="color:white; font-size:20px; padding:0px"></i> Add to Runlist</button>
     <button class="button2" type="submit" value="sold" name="sold"><i class="fa fa-cart-plus" style="color:white; font-size:20px; padding:0px"></i> Add to Sold</button>
     <button class="button2" type="submit" value="shop" name="shop"><i class="fa fa-wrench" style="color:white; font-size:20px; padding:0px"></i> Add to Shop</button>
     <button class="button2" type="submit" value="delete" name="delete"><i class="fa fa-trash" style="color:white; font-size:20px; padding:0px"></i> Delete</button>

 </form>

Once selected the php document will run called tester.php. Here is the code that I am trying to use for the php to understand which button is pressed.

<?php

if (isset($_POST['runlist'])){
    echo 'Runlist pressed';
}
else if (isset($_POST['sold'])){
    echo 'sold pressed';
}
else if (isset($_POST['shop'])){
    echo 'shop pressed';
}
else if (isset($_POST['delete'])){
    echo 'delete pressed';
}

}
?>

Of course I am misunderstanding something because it only works when I have only 1 if statement. Please help, thank you for your time.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • else if should be elseif – Grant Apr 03 '18 at 13:16
  • 1
    @Grant — No. [Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example](http://php.net/manual/en/control-structures.elseif.php) – Quentin Apr 03 '18 at 13:21
  • Andrew, what have you tried to debug this problem? – Nico Haase Apr 03 '18 at 13:22
  • When I run this code, it errors with *Parse error: syntax error, unexpected '}', expecting end of file in /Users/XXXXX/tmp/jkfdjfkdjk/index.php on line 24*. If I remove the `}` on the penultimate line, it works perfectly. Voting to close as off-topic because the only issue I can find is caused by a typo. – Quentin Apr 03 '18 at 13:23
  • Thank you Quintin! It works! – Andrew Richards Apr 03 '18 at 13:28

0 Answers0