<?php
session_start();
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
header('Content-Type: application/json; charset=utf-8');


if(isset($_POST['user_id']) && isset($_POST['app_id']) && isset($_POST['promo']))
{
    
include 'config.php';
$user_id=$_POST['user_id'];
$app_id=$_POST['app_id'];
$promo=$_POST['promo'];

$user_id=stripslashes($user_id);
$user_id=mysqli_escape_string($con, $user_id);

$app_id=stripslashes($app_id);
$app_id=mysqli_escape_string($con, $app_id);


$promo=stripslashes($promo);
$promo=mysqli_escape_string($con, $promo);



$date_t = date("d-m-Y");
$date_t2 = date("m/d/Y");
$date_t2 = strtotime($date_t);


     $promo_query = $con->prepare("SELECT promo_type FROM promo WHERE code = ?");
        $promo_query->bind_param("s", $promo);
        $promo_query->execute();
        $promo_result = $promo_query->get_result();

        if ($promo_result->num_rows > 0) {
            
            $sql3=mysqli_query($con,"UPDATE applications SET `application_fee`='Paid' WHERE user_id='$user_id' AND application_id = '$app_id'");
            
                        echo json_encode(['status' => true, 'success' => 'Successful']);

               } else {
            echo json_encode(['status' => false, 'success' => 'Invalid promo code']);
            exit();
        }
    



}
else
{
$status = false;
$suc = "Incomplete Parameters";

$output = array('status' => $status, 'success'=>$suc);
echo json_encode($output); //output JSON data

}

?>