IF条件在UPDATE查询中不起作用

时间:2017-11-17 06:10:19

标签: php mysqli

在此代码中,当我想要将状态从Pending更改为Accepted时,If语句不起作用。 在数据库中,我默认保持Pending。问题是,当我要更新状态时,STATUS将更新,但If条件内的代码无法工作。 请帮我解决这个问题。 提前谢谢。

 <?php
include("connect.php");//conection
if(isset($_REQUEST['leave_id']))
{
$id=$_REQUEST['leave_id'];
}
else
{
$id=NULL;
}
$result = mysqli_query($con,"SELECT TAKEN_LEAVES,BALANCE_LEAVE,STATUS 
                              FROM xxxemi_person_leave_t
                              WHERE leave_id= $id");
$res = mysqli_fetch_array($result);
if (!$result) 
		{
		die("Error: Data not found..");
		}
	
	$taken_leave = $res['TAKEN_LEAVES'];
	$balance_leave = $res['BALANCE_LEAVE'];
	$status = $res['STATUS'];

    if(isset($_POST['save']))
          {
		  if ($status=='ACCEPTED')
		  {
		 $status = $_POST['USTATUS'];
		 $updated_balance_leave = $_POST['UBALANCE_LEAVE'];

		 $updated_balance_leave = $balance_leave - $taken_leave;		 
	         
		 mysqli_query($con,"UPDATE xxxemi_person_leave_t 
		                    SET STATUS ='$status', BALANCE_LEAVE ='$updated_balance_leave'
				    WHERE leave_id = '$id' "); 

	       echo "<script>alert('Your Record Updated');</script>";
	      
		   }

		    else 
		  {
		   $status = $_POST['USTATUS'];
		  
		 mysqli_query($con,"UPDATE xxxemi_person_leave_t 
		                    SET STATUS ='$status' 
				    WHERE leave_id = '$id' "); 

	       echo "<script>alert('Your Record Updated');</script>";
	      
		   }
  }
		  	
    mysqli_close($con);
?>
/**************PHP CODE *******/
   <form method="post">
             <td><input type="hidden" name="id" value=<?php echo $_GET['leave_id'];?>>
	
             <input type="hidden" name="UBALANCE_LEAVE" value="<?php echo $updated_balance_leave;?>">

              <input type="checkbox"  name="USTATUS" value="ACCEPTED" />
              <img src="images/Approved.png" />&nbsp;&nbsp;&nbsp;

              <input type="checkbox" name="USTATUS" value="REJECTED" />
              <img src="images/Rejected.png" /></td>

              <input type="submit" name="save" value="Update">
            </form>
/************* HTML CODE**********/

1 个答案:

答案 0 :(得分:0)

看来你正在使用$statu = $res['STATUS']; // STATUS $statu STATUS,但是如果条件正在检查$status

更改此

if ($status=='ACCEPTED')

 if($_POST['USTATUS']=='ACCEPTED')

AND type="checkbox"type="radio"