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!"; } ?>
Advertisement
Answer
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 }