I am having a table which has the fields: staff_id, leave_applied_from, leave_applied_to.
+----------+--------------+------------+
| staff_id | applied_from | applied_to |
+----------+--------------+------------+
| 1 | 2012-06-21 | 2012-06-21 |
| 2 | 2012-06-21 | 2012-06-23 |
+----------+--------------+------------+
So the requirement is, If the staff_id 1 tries to enter the date 2012-06-21 it should not allow to enter it, if staff_id 2 tries to enter the date 2012-06-22 it should not allow the staff to enter.
I know how to show errors in PHP side, but I don’t know how to check the database whether the date is there in the DB, I don’t know how to check both the fields in one single MySQL query.
The query should check for staff_id first and then both the other fields(applied_from, applied_to). If the staff has entered the same date range already it should give error.
Please try the below:
If the query returns record, that means the key in date is within range and you could prompt error.