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

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

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 :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊