-2

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.

Chathurika
  • 419
  • 2
  • 6
  • 18
  • can you be more specific? I do not really get what you want to do. Further: '.' is useless and can be removed. ' – JRsz Jun 01 '16 at 09:11
  • 3
    Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) its really pretty easy – RiggsFolly Jun 01 '16 at 09:16
  • 1
    Do you have a `
    ` tag in your HTML anywhere. I think you are getting the process of clicking an `` anchor tag mixed up with submitting a form. They are seperate concepts and work differently!
    – RiggsFolly Jun 01 '16 at 09:19

2 Answers2

2

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.

Archish
  • 850
  • 8
  • 32
1

Hi Please try this.

leave_request.php

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

    if(isset($_GET['leave_id'])){
       $id2=$_GET['leave_id'];
        $result= "UPDATE emp_leaves  SET approval_status='Accepted' WHERE leave_id='$id2'";
        $query=mysql_query($result);
    }
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44