I have some really strange issue with nested if else. The code looks correct to me.
Working on this for hours and It doesn't make sense.
So basically on the nested if statement, I do a quick check to make sure 0 rows in last 1 minute, to avoid a double entry.
Then if rows are == 0, Burn the data, send email, and redirect to success.
99% of the time, it will, Burn data, fire email, then jump over to the nested else statement and redirect to the gone-wrong page.
I can't see what would make the code run twice.
It actually has fired a payment-success like 1 or 2 times.
Is this a cache problem?
If i run it within 1 min it goes to the nested else as expected.
I have no errors in the log.
Bring on the down votes!
<?php
if(isset($_SESSION['ewayamount']) && (!empty($_SESSION['ewayamount'])) ) {
$depot_id = $_SESSION["memberID"];
$description = 'Credit Top Up';
$my_date = date("Y-m-d H:i:s");
$credit = $_SESSION['ewayamount'] / 100;
$ip = $ip = $_SERVER['REMOTE_ADDR'];
$useragent = $useragent = $_SERVER['HTTP_USER_AGENT'];
$email = $_SESSION['email'];
$sql = "SELECT count(*) FROM members_accounts WHERE memberID = '$depot_id' AND ip = '$ip' AND description = '$description' AND date >= NOW()- INTERVAL 1 MINUTE";
$stmt = $db->prepare($sql);
$stmt->execute();
$rows = $stmt->fetchColumn();
if ($rows == 0 ) {
$stmt = $db->prepare("INSERT INTO members_accounts (memberID, description, date, credit, ip, useragent)
VALUES (:depot_id, :description, :my_date, :credit, :ip, :useragent)");
$stmt->execute(array(
':depot_id' => $depot_id,
':description' => $description,
':my_date' => $my_date,
':credit' => $credit,
':ip' => $ip,
':useragent' => $useragent
));
include_once('payment-receipt.php');
$success = "payment-success.php" ;
header( "Location: $success" );
exit() ;
} else {
$gonewrong = "payment-wrong.php" ;
header( "Location: $gonewrong" );
exit() ;
}
} else {
$failed = "payment-failed.php" ;
header( "Location: $failed" );
exit() ;
}
?>
Aucun commentaire:
Enregistrer un commentaire