Chathurika Chathurika - 6 months ago 8
PHP Question

PHP Onclick action for a button

following is my code that I have used,

if ($status=='Pending'){
echo '<td>'.'<a href="leave_request.php?leave_id='.$id1.'"><input type="button" name="submit" class="btn btn-success" value="Approve" "></button></a>'.'</td>'

if(isset($_POST['submit'])){
$id2=$_GET['leave_id'];
$result= "UPDATE emp_leaves SET approval_status='Accepted' WHERE leave_id='$id2'";
$query=mysql_query($result);
}
}





When user click Accept button, URL will get leave_id of clicked leave_request and will reload page itself. I want to update leave_status column of identified leave_id as 'accepted' while reloading the page. How can I do it.

Answer

you are passing value in query string, so $_POST will not work. you need to use $_GET or $_REQUEST.

change your if condition like this.

if(isset($_GET['leave_id'])){

this might solve your problem.

Comments