I want to implement a web app with php and mysql, to book an hotel
and I want to create a constraint so the date of departure cannot be before the arrival date here are the method that I've tried without success :
ALTER TABLE reservation WITH CHECK ADD CONSTRAINT CONSTRAINT check_dates
CHECK ( DATEARRIVEE < DATEDEPART)
messe error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHECK ADD CONSTRAINT CONSTRAINT check_dates
Asked
Active
Viewed 187 times
0

kamel berkani
- 57
- 1
- 6
-
See https://stackoverflow.com/questions/2115497/check-constraint-in-mysql-is-not-working – Bill Karwin Feb 20 '19 at 20:18
1 Answers
0
I suggest you to do the checks back-end side in your php code before inserting records in the table and front-end side with js. If the arrival date is > of the departure date you don't have to make a request to your server, so your js must handle this problem. For more security just before execute the query you can add another check.

Manuel Espinosa
- 108
- 12