-1

I am trying to implement a php/mysql statement which only allows users to delete a record at a certain date/time. Users can currently delete a record at anytime. However as it is a booking system, there should be 2 days notice whenever user wants to cancel a booking. Therefore i would like to know how to make a function which prevents users from cancelling a booking that is less than 2 days from the booking date/time.

My table currently has the following fields which are BookingDate and Timeslot.

Here is a snippet of code which currently does the mysql delete function.

 $id = $_GET['id'];

 $query1="DELETE from bookings1 where booking_id='$id'";

 $results = $mysqli->query($query1);

What I would like to do is to validate this delete function to prevent users from deleting records that is less than 48 hours of the booking date ?

r123456
  • 21
  • 5

1 Answers1

0

In general, I advocate developing an API for applications. That means that the application speaks to the database using stored procedures and views, rather than directly using SQL queries.

A primary reason for this is that additional logic can be implemented in the stored procedures. So, if you had a usp_delete_booking stored procedure, then the logic could be implemented there, returning a nice error message when called.

The alternative is to implement a trigger that does the testing. This gets complicated when you start introducing more advanced permissions -- so a user can't normally delete a booking two days before. But a supervisor can. Or, under certain circumstances, you might allow it. The trigger will have to implement all the logic, because it is hard to circumvent.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786