duanchao5258
2016-08-12 10:47
浏览 23
已采纳

表单提交后,变量不会更改

the problem is that my variable $target_time doesn't work well.

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
}

When user press a submit button, the element value, which name is bid is executing by if (isset($_POST['bid'])) { but the $target_time isn't more than $current_time and it just simply executing 1470996804 >= 900 instead of adding 15 minutes to the form submitting date. Because it gives the result of 1470996804 >= 900, which in the if ($current_time >= $target_time) { condition is true, it is executing immediately after submiting the form and $stmt13->execute(); is executed, so it removes all table content. What should I do to make when the form is submitted, $target_time would be taken from the database and the if ($current_time >= $target_time) { condition wouldn't be true immediately but executed only after 15 minutes when the submit button was pressed?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujieluo5875 2016-08-12 13:16
    已采纳

    I've solved it by myself. Yes, $stmt14 is a PDO statement and it's fetched before the execution. Just used this condition instead: if ($current_time >= $target_time && $stmt2 >= 1) { where $stmt2 is a PDO count statement, so it makes sure there is though 1 row and then it grabs the value of the last inserted row :)

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题