我有一个代码,用户将数据发送到数据库,这些数据包括时间。我试图设置脚本以防止用户每30分钟仅发送一次数据。这是我尝试的代码,但它不起作用。
if($_SERVER['REQUEST_METHOD']=='POST'){
$username = $_POST['username'];
$points= $_POST['points'];
$date= $_POST['date'];
$data = "SELECT date FROM tracker WHERE (username ='$username' ORDER BY date DESC LIMIT 1)";
$data_result = $connect->query($data);
$re = $data_result->fetch_assoc();
if($re["date"] <= strtotime('-30 minute')){
echo '0';
}}
答案 0 :(得分:0)
您可以将当前日期时间与上次日期时间的差异计算为
SELECT TIMESTAMPDIFF(MINUTE, date, now()) as mins FROM tracker WHERE username ='$username' ORDER BY date DESC LIMIT 1
确保日期列的数据类型应为datetime