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

后端 未结 4 2055
我在风中等你
我在风中等你 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

    You can easily do that, using the DATEDIFF method.

    It will be my first comment. so, Let me know if I have written something incorrectly here.

    $currentDate = date('Y-m-d');
    
    $query = "SELECT DATEDIFF($currentDate,*Last_update_date_row_name*) as diff FROM *TABLE_NAME* WHERE user_id=Current_User_Id";
    
    $result = mysqli_query($conn,$query);
    
    if($result!=false){
      //compare the diff with your desire number
      // then you can hide or disable the button or show error
    }
    

提交回复
热议问题