<?php include("../cn.php");

$driver = $_REQUEST["id"];
// $customer = $_REQUEST["driver"];
$bookingno = $_REQUEST["BookingNo"];

$sql = "UPDATE rentedcars SET `status`='Pending', `driver_id`=NULL WHERE  `BookingNumber`='$bookingno' AND `driver_id`='$driver' AND `StartTime` is NULL ";

// $myfile = fopen("testfile.txt", "w");
// fwrite($myfile, $sql);
// fclose($myfile);

$result = mysqli_query($connect, $sql);
// $response["count"] = mysqli_affected_rows($result);

$query = "UPDATE driver SET driver_availability = 'yes' WHERE driver_id = $driver";
    
$result1 = mysqli_query($connect, $query);

if ($result && $result1)
{
$response["code"] = "200";
$response["msg"] = "Ride Cancelled Successfully";
}
else
{
    $response["code"] = "202";
    $response["msg"] = "Trip Started, Ride cannot be cancelled.";
}

echo json_encode($response);

?>