在我的脚本中,我想获取登录用户的最后一个 send_time。如果这个 send_time 与当前时间至少有 10 分钟的时间差,他将能够发布新的东西,否则他会收到一条错误消息.
但是,当我尝试此操作时,自有人发布的最后一个帖子以来,没有人能够发布至少 10 分钟。
$email = $_SESSION['login'];
if ($link)
{
$check="SELECT TIMESTAMPDIFF(MINUTE, send_time, CURRENT_TIMESTAMP) AS 'diff' FROM bloopp WHERE email = '$email' ORDER BY bloopp_id DESC LIMIT 1" or die("Error " . mysqli_error($check));
$res = mysqli_query($link, $check) or die("Error " . mysqli_error($res));
$data = mysqli_fetch_array($res, MYSQLI_ASSOC);
if($data['diff'] <= "10")
{
echo "You posted not so long ago.";
}
else
{
$sql="INSERT INTO bloopp (bloopp, browser, medium, send_time, email) VALUES ('$bloopp', '$browser', 'desktop', NOW(), '$email')";
$result = mysqli_query($link, $sql);
if($result)
{
header('Location: index.php');
}
else
{
echo "Something has gone wrong. We’re sorry.";
}
}
}
else
{
echo "ERROR";
}