Я втрое проверял это примерно 50 раз. Запрос с такими же параметрами работает непосредственно в sql. Я даже не получаю ошибки. Я опубликую под функцией php и где я ее называю. Мой запрос на получение строки данных для заполнения входных данных формы работает нормально, я дважды проверил имя действия, имя переменных, я схожу с ума.
PHP function
function editReservation($connection, $reservation){
$result = NULL;
$query = "UPDATE bookings
SET reservation_type=?, reservation_date=?,
reservation_time=?, special_requirements=?,
party_size=?
WHERE reservation_code=?";
if($stmt = $connection->prepare($query)){
$stmt->bind_param('ssssss',
$data['reservation_type'], $data['reservation_date'],
$data['reservation_time'], $data['special_requirements'],
$data['party_size'], $data['reservation_code']);
if($stmt->execute()){
$result = TRUE;
}
$stmt->close();
}
return $result;
}
AJAX Обработчик
elseif($_POST['action'] == 'editBookingByCode'){
$data = array(
"reservation_type" => $_POST['reservation_type'],
"reservation_date" => $_POST['reservation_date'],
"reservation_time" => $_POST['reservation_time'],
"special_requirements" => $_POST['special_requirements'],
"party_size" => $_POST['party_size'],
"reservation_code" => $_POST['code'],
);
$updated = editReservation($connection, $data);
echo $updated;
exit();
}
AJAX
$("#editBooking").submit(function( event ) {
event.preventDefault();
var firstName = $('#firstName').val();
var lastName = $('#lastName').val();
var email = $('#email').val();
var number = $('#number').val();
var date = $('#date').val();
var time = $('#time').val();
var size = $('#size').val();
var occasion = $('#occasion').val();
var comment = $('#comment').val();
let bookingData = {
action: "editBookingByCode",
code: "<?=$booking['reservation_code']?>",
reservation_type: occasion,
reservation_date: date,
reservation_time: time,
special_requirements: comment,
party_size: size
};
console.log(bookingData);
$.ajax({
type: 'POST',
url: "/modules/ajax/ajax_handler.php",
data: bookingData
})
.done((result)=>{
if(result.message == "Success"){
location.reload();
}else{
alert('An error occured, failed to edit booking option, please try again');
}