表单提交后,变量不会发生变化

时间:2016-08-12 10:47:10

标签: php forms

问题是我的变量$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分钟后执行按下了吗?

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题。是的,$stmt14是一个PDO语句,它在执行之前被提取。只是使用了这个条件:if ($current_time >= $target_time && $stmt2 >= 1) {其中$stmt2是一个PDO计数语句,所以它确保有一行然后它抓取最后一个插入行的值:)

相关问题