-1

What I want is to update the arrival date of my reservations table by adding one day to it. What I tried is the following:

$reservationId=$_GET['reservationId'];

$getArrivaldate="SELECT arrival_date from reservations WHERE reservation_id=$reservationId;";

$getArrivalResult=mysqli_query($conn,$getArrivaldate);
$rowArrivalDate=mysqli_fetch_array($getArrivalResult);

$arrivalDate=$rowArrivalDate['arrival_date'];

$newArrivalDate=date('Y-m-d',strtotime($arrivalDate . "+1 days"));

$noShowReservation="UPDATE reservations SET $arrivalDate = $newArrivalDate WHERE reservation_id=$reservationId ;";

if(mysqli_query($conn,$noShowReservation))

{
header("Location:../public/home.php?reservation=moved");
exit();
}
else{
echo"ERROR";
}

But when I excecute the query on xammp I get the error "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''2021-02-05' = '2021-02-06' WHERE reservation_id=104' at line 1".. What am I missing here ?

Nikos
  • 1
  • 2
  • In your update query you have `$arrivalDate` but that's not a column name. Use `arrival_date`, but see Gab's answer below. – Tangentially Perpendicular Feb 05 '21 at 00:00
  • Please learn to use prepared statements, inserting variables into strings is not how to build SQL queries. It's insecure and leads to problems when you don't remember to put quotes around things. I would also strongly recommend not using mysqli; it was never designed for direct use and is needlessly obtuse and verbose. – miken32 Feb 05 '21 at 00:22

1 Answers1

1

You can do it directly in MySQL:

UPDATE reservations
SET arrival_date = arrival_date + INTERVAL 1 DAY
WHERE reservation_id = 1
Gab
  • 3,404
  • 1
  • 11
  • 22