<?php

require_once('Conn.php');
header('Content-Type: application/json');

if($_SERVER['REQUEST_METHOD'] != 'POST') {
    header('HTTPS/1.1 405');
    echo json_encode(array(["message" => "method not allowed" , "status" => "false"]));
    exit;
}

$params = json_decode(file_get_contents('php://input') , true);

if($params == null ||  !isset($params['ucid']) || !isset($params['user_ratings']) || !isset($params['user_feedback']) ) {
    echo json_encode(array(["message" => "internal body error" , "status" => "false"]));
    exit;
}

$ucid = $params['ucid'];
$user_ratings = $params['user_ratings'];
$user_feedback = $params['user_feedback'];


$query = "UPDATE users_complaint u SET u.user_ratings = $user_ratings , u.user_feedback = '$user_feedback' WHERE u.ucid = $ucid";
$result = mysqli_query($connection , $query);
if($result) {
    echo json_encode(array(['message' => 'Thanks for your review' , 'status' => 'true']));
}
else{
    echo json_encode(array(['message' => mysqli_error($connection) , 'status' => 'false']));
}

?>
