Page 1 of 1

Problem recieving result to both change db and send mail.

Posted: Fri May 16, 2008 1:12 pm
by ashebrian
Hi i have a problem with my php and mySql code. Once a transaction is completed and successfull it will return the result 00 but i can't seem to change the status of the order to paid in the db and send myself an email to let me know of the order. Can you please help. The code is below:

Code: Select all

if ($result == "00") {
            
        // check that the invoice has not been previously processed
        $sql = "SELECT od_status
                FROM tbl_order
                WHERE od_id = {$_POST['ORDER_ID']}";
 
        $result = dbQuery($sql);
 
        // if no invoice with such number is found, exit
        if (dbNumRows($result) != "00") {
            exit;
        } else {
        
            $row = dbFetchAssoc($result);
   $_SESSION['mydatabase_od_id'] = $row['od_id'];
            
            // process this order only if the status is still 'New'
            if ($row['od_status'] !== 'New') {
                exit;
            } else {
 
     
                    // ok, so this order looks perfectly okay
                    // now we can update the order status to 'Paid'
                    // update the memo too
                    $sql = "UPDATE tbl_order
                            SET od_status = 'Paid', od_memo = '$memo', od_last_update = NOW()
                            WHERE od_id = '{$row['od_id']}'";
                    $result = dbQuery($sql);
                }
            }
/* --------------------------------------------------------------
 Send notification email to yourself.
 */
if ($shopConfig['sendOrderEmail'] == 'y') {
    $subject = "[New Order] " . $_SESSION['orderId'];
    $email   = $shopConfig['email'];
    $message = "\n A customer has sent you a new order. Follow the link for the order details \n http://" 
                . $_SERVER['HTTP_HOST'] . '/my/orders/index.php?view=detail&oid=' 
                . $_SESSION['orderId'] 
                . "\n If you cannot open the link or are having problems logging in to your account please contact the Site Administrator. \n" ;
    mail($email, $subject, $message, "From: $email\r\nReturn-path: $email");
}
 
?>
 
Thank you
<br/><br/>
To continue browsing please <a href="http://yourdomain.com"><b><u>click here</u></b></a>
<br/><br/>
 
<?
} else {
?>

Re: Problem recieving result to both change db and send mail.

Posted: Fri May 16, 2008 10:12 pm
by nowaydown1
It's going to be tough to help you with this. I took a look at what you posted, if I had to pick a starting point, I would take a look at:

Code: Select all

 
if (dbNumRows($result) != "00") {
 
If that function really does return the number of rows, I certainly wouldn't expect it to return "00". Maybe your wrapper stuff is funky. Who knows :) My advice would be to get in there and get your hands dirty. Put in die statements around those conditionals and figure out what's really happening with the logic flow. What does that dbNumRows($result) call actually return? Do a print_r on your $row variable after the dbFetchAssoc call. Does the array actually contain an od_id column that has it's value equal to 'New'?

Re: Problem recieving result to both change db and send mail.

Posted: Sun May 18, 2008 8:05 pm
by ashebrian
The code was actually set as:

Code: Select all

if (dbNumRows($result) == 0)
And that was the area i've been looking at before you mentioned it. As for the print_r ($row); code at the location you described, Nothing is displayed at all.

I took this code from another place on my site (and added it to the rest of the code as i have shown you in previous message) to be able to update to the status Paid, once a result is 00.

Code: Select all

#        // check that the invoice has not been previously processed
#         $sql = "SELECT od_status
#                 FROM tbl_order
#                 WHERE od_id = {$_POST['ORDER_ID']}";
#  
#         $result = dbQuery($sql);
#  
#         // if no invoice with such number is found, exit
#         if (dbNumRows($result) == 0) {
#             exit;
#         } else {
#        
#             $row = dbFetchAssoc($result);
#    $_SESSION['mydatabase_od_id'] = $row['od_id'];
#            
#             // process this order only if the status is still 'New'
#             if ($row['od_status'] !== 'New') {
#                 exit;
#             } else {
#  
#      
#                     // ok, so this order looks perfectly okay
#                     // now we can update the order status to 'Paid'
#                     // update the memo too
#                     $sql = "UPDATE tbl_order
#                             SET od_status = 'Paid', od_memo = '$memo', od_last_update = NOW()
#                             WHERE od_id = '{$row['od_id']}'";
#                     $result = dbQuery($sql);
#                 }
#             }
Also, The $result needs to be assigned as the transaction coming back from the 3rd party will tell u if the transaction is successful or not. However, my database also has $result assigned so i have a bit of a problem. I might have to change the whole db $result or maybe another way can be done?

Re: Problem recieving result to both change db and send mail.

Posted: Wed May 21, 2008 6:23 am
by ashebrian
Sorted.......decided not to use the db. will just send mail and will change the status manually