如何限制用户多久可以将mysql值更新到数据库 [英] How to limit how often a user can update a mysql value to a database

查看:97
本文介绍了如何限制用户多久可以将mysql值更新到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个字段,用于更新mysql数据库中的值.我要这样做,以便用户只能每3天更新一次值.我将如何去做?

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?

这是我到目前为止编写的代码:

Here is the code that I have written so far:

<?php
        if(isset($_POST['Update'])){
          $UpdateHWID = $_POST['HWID'];

          $sql = $con->query("UPDATE users SET HWID = '{$UpdateHWID}' where UserID = $User");

          echo "HWID Updated Successfully!";
        }
?>

推荐答案

在db(last_update)type = data中创建新行

Create new row into db (last_update) type= data

//return to sql last_update (select db ...)

$current_Data = date ('Y-m-d');
$current_Data_time = strtotime ($current_Data); //convert data to time
$last_update_p3 = strtotime ("+3day", strtotime($last_update));
$last_update_p3 = strtotime ($last_update_p3);//convert data to time

if($current_Data_time <=$last_update_p3)
{
 $sql = $con->query("UPDATE users SET HWID = '{$UpdateHWID}' , last_update='{$current_Data}'  where UserID = $User");
//update last data with current date 
}
else
{
//It has not gone three days 
}

这篇关于如何限制用户多久可以将mysql值更新到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆