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?
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 :)
Collected from the Internet
Please contact javaer1[email protected] to delete if infringement.
Comments