<?php

require 'db.php';

$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
if(isset($postdata) && !empty($postdata))
{
$val = mysqli_real_escape_string($con, trim($request->value));
if($val != null)
{
    $s_sql = "SELECT * FROM coupon_code where id = '$val'";
    $s_query = mysqli_query($con,$s_sql);
    if($rows = $s_query->fetch_assoc())
    {
        $status = $rows['status'];
    }
    if($status == 0)
    {
        $sc_sql = "UPDATE coupon_code set status = '1' where id='$val'";
        $sc_result = mysqli_query($con,$sc_sql);
        if($sc_result)
        {
            $rows = array('status'=>true,'message' => 'Status Updated');
            echo json_encode($rows);
        }
    }
    else if($status == 1)
    {
        $sc_sql = "UPDATE coupon_code set status = '0' where id='$val'";
        $sc_result = mysqli_query($con,$sc_sql);
        if($sc_result)
        {
            $rows = array('status'=>true,'message' => 'Status Updated');
            echo json_encode($rows);
        }
    }
}
else
{
    $rows = array('status'=>false,'message' => 'Something Error');
    echo json_encode($rows);  
}
}

?>