What is the correct format for UPDATE if exists else insert in this situation - I have managed to do update and insert separately but need them together?.
What I want is that - if the date exists then it gets updated to fullday, and if it doesn't exist then a new row with the new details gets inserted.
$date = (isset($_POST['date']) ? $_POST['date'] : null);
$reservationType = (isset($_POST['reservation-type']) ? $_POST['reservation-type'] : null);
$connect = new mysqli($servername, $username, $password, $dbname);
// check connection 
if ($connect->connect_error) {
    die("connection failed: ". $connect->connect_error);
}
$sql = "SELECT * FROM reservations";
$result = $connect->query($sql);
if ($result -> num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        if ($date == $row['date_of_reservation']) {
           "UPDATE reservations SET reservationType = 'FULLDAY' WHERE   date_of_reservation='$date'";
    }
    else {
        "INSERT INTO reservations (date_of_reservation, reservationType) VALUES ('$date', '$reservationType')";
        }
    }
}
 
    