duancheng6500 2012-04-27 09:05
浏览 73
已采纳

将用户输入字符串与mysql中的curdate进行比较

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?

  • 写回答

1条回答 默认 最新

  • douwu3763 2012-04-27 09:21
    关注

    (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 your INSERT statement, 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真