【发布时间】:2016-08-12 10:47:09
【问题描述】:
问题是我的变量$target_time 不能正常工作。
if (isset($_POST['bid'])) {
$stmt10->execute(array(
'user_id' => $usid,
'user' => $login,
'bid' => $_SESSION['bid']
));
}
$target_time = strtotime('+15 minutes', strtotime($stmt14));
$current_time = time();
echo $current_time . ' >= ' . $target_time;
$seconds_left = $target_time - $current_time;
$minutes_left = floor($seconds_left / 60);
$seconds_left -= $minutes_left * 60;
$seconds_left = floor($seconds_left);
if ($current_time >= $target_time) {
$stmt9->execute();
$r1 = $stmt9->fetch(PDO::FETCH_ASSOC);
$stmt12->execute();
$r2 = $stmt12->fetch(PDO::FETCH_ASSOC);
$stmt11->execute(array(
'win' => $r1['bid'],
'user_id' => $r2['user_id']
));
$stmt13->execute(); // Clears bid table
}
当用户按下提交按钮时,名为bid 的元素值由if (isset($_POST['bid'])) { 执行,但$target_time 不超过$current_time,它只是简单地执行1470996804 >= 900 而不是添加距离表格提交日期还有 15 分钟。因为它给出了1470996804 >= 900的结果,在if ($current_time >= $target_time) {条件为真时,它在提交表单后立即执行,$stmt13->execute();被执行,所以它删除了所有表格内容。提交表单时我该怎么做,$target_time 将从数据库中取出,if ($current_time >= $target_time) { 条件不会立即为真,而是仅在按下提交按钮 15 分钟后执行?
【问题讨论】:
-
我很难理解你在问什么。您是否希望在用户提交表单 15 分钟后执行查询?
-
是的,这正是我想要的。
-
我没有看到任何错误,它只是在用户提交表单后执行,而不是延迟 15 分钟。
-
我不想每 15 分钟执行一次。这是一个拍卖计时器,如果用户的出价没有超过之前的出价,那么在 15 分钟后,之前的用户中奖。
-
$stmt14的值是多少?看起来这不是一个有效的时间,所以strtotime($stmt14)正在返回0,当你再加上 15 分钟时,它只是900,不是现在的时间。