I’m working on a php/mysql app that strongly rely on a correct date. To ensure that the date inserted into the database is always correct and since php/mysql date functions rely on the system clock, i decide to ask users to input the current date in the date form field and then compare it with the current date in the database using CURDATE() before inserting any data into the database.
I don’t know if this is the right way to go about it or is their a better solution to enure date integrity?
(Upgrading to an answer)
One would typically rely on the system clock to be correct; it is something that is much more under one’s own control than user input, which can be either deliberately or accidentally incorrect.
I would recommend using
CURDATE()as a value in yourINSERTstatement, and undertaking measures such as running a Network Time Protocol client to keep your system clock correct. Most modern operating systems not only include such software by default, but they are typically configured and working out-of-the-box.If your system is standalone and unable to update its time from the network, you might consider any combination of: receiving a time signal from another source (such by radio, like the NPL signal); verifying the system clock periodically (especially on boot); monitoring the CMOS battery and ensuring that it is replaced in a timely fashion; or employing rechargeable batteries.