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.

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路