php - How to perform same event on two different buttons? -
i have piece of code below, supposing display no request when no data in database , display request accept , reject button when data in database. how should write code in order make accept , reject button perform action?
<?php $travelrequest = $user->usertravelrequest($userid); if(!$travelrequest){ echo '<div class="requestbox"> <p> have no request others @ moment. </p> </div>'; } else { foreach($travelrequest $request){ echo '<div class= "requestbox"> <p>'. $request->trip_name.'</p> <p>organised '.$request->username.'</p>'; ?> <form method="post"> <div class = "ar-btn"> <input type="button" name="accept" value="accept"/> <input type="button" name="reject" value="reject"/> <p></p> </div> </form> </div> <?php } } ?>
use type="submit"
instead of type="button"
, , give them same name. they'll submit form, , script can test button used value of parameter.
<input type="submit" name="action" value="accept"/> <input type="submit" name="action" value="reject"/>
you test with:
if (isset($_post['action'])) { if ($_post['action'] == 'accept') { // add database } elseif ($_post['action'] == 'reject') { // delete database } }
Comments
Post a Comment