How to limit how often a user can update a mysql value to a database

后端 未结 4 2123
我在风中等你
我在风中等你 2021-01-24 16:51

I have a field on my website, which updates a value in my mysql database. I want to make it so the user can only update the value every 3 days. How would I go about doing this?<

4条回答
  •  情书的邮戳
    2021-01-24 17:36

    According to Pinx0, if you add a new column to your users table which contains the date of the last update, then you can create a condition. For example:

    ALTER TABLE `users` 
    ADD `lastUpdated` DATE NOT NULL;
    

    Now you can add a condition to your existing query something like this:

    UPDATE `users` 
    SET `HWID` = '{$UpdateHWID}',
        `lastUpdated` = NOW()
    WHERE `UserID` = $User AND 2 < DATEDIFF(CURDATE(),`lastUpdated`);
    

提交回复
热议问题