roldahayes Posted October 7, 2014 Share Posted October 7, 2014 Hi, I have a section of code that sends an order confirmation to me when a customer places an order with us. This all works fine but recently, I have started to get duplicate confirmations coming from the same customers, one in particular, many times a day... Is there anything obvious about this code that could be causing it? Thanks, <?php //get info from shopper table$sqlquery = "SELECT * FROM shopper WHERE user_ID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result); // if no matches then nothing to checkoutif ($rowCount == 0){echo ("<p><font class=error>Your basket was empty. You have come to this page in error!!<br>Please return to the main site</font></p>");return;}else{ //store shopper details$shoprow = mysql_fetch_assoc($result);$Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2);$Post_type = htmlspecialchars($shoprow['Postage']);$Postage = htmlspecialchars($shoprow['Postage']);$custdetails = explode("\n",$shoprow["Customer_Address"]);foreach($custdetails as $value) {if(strpos($value,"Customer_Name") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Surname") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Business_name") !== false) { $Additional_Details .= "$value\n"; }}//get basket details$sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);if ($rowCount == 0){echo "<font class=error><p>Error: Your basket was empty.</p></font>";return;}else{// select the userID's basket query and the Product Reference relating to each of the basket's productID's$sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";//echo $sqlquery;$baskresult = mysql_query($sqlquery);$rowCount = mysql_num_rows($baskresult); //set counter to name each hidden form element for the product details$frmCount = 1; $strBody = "Order Details are as follows\n\n";$strBody = $strBody . "ShopperID : ".$shopperID."\n\n";$strBody = $shoprow["Customer_Address"]."\n\n";//get alternate delivery details$strBody = $shoprow["Delivery_Address"]."\n\n";$strBody = $shoprow["Search_Engine"]."\n\n";while ($row = mysql_fetch_assoc($baskresult)){ //cut the prod_type variable//get the length of the variable$strLength = strlen ($row["Prod_Type"]);//assign first 2 characters of variable$strPrefix = substr($row["Prod_Type"], 0, 2);//debug//echo "\n prefix :" . $strPrefix;//assign remaining characters of variable$strSuffix = substr($row["Prod_Type"], 2, $strLength);//debug//echo "\n suffix :" . $strSuffix; //set product header image depending on the Prod_Type Code//start the table row$strProdType = prodType ($strPrefix); $strBody = $strBody ."Order : ".$frmCount;$strBody = $strBody ."\nCarmake : ".htmlspecialchars($row['Car_Make']);$strBody = $strBody ."\nProduct Type : ".$strProdType;$strBody = $strBody ."\nProduct Make : ".htmlspecialchars($row['Prod_Make']);$strBody = $strBody ."\nProduct Description : ".htmlspecialchars($row['Product_Desc']);$strBody = $strBody ."\nProduct reference : ".htmlspecialchars($row['Prod_REF']);$strBody = $strBody ."\nQuantity : ".htmlspecialchars($row['quantity']);$strBody = $strBody ."\nProduct Price : ".number_format(calcVAT(htmlspecialchars($row['Price_ExVat'])), 2);$strBody = $strBody ."\n"."End of order ".$frmCount."\n\n";$frmCount ++; }//end while $strBody = $strBody .$Additional_Details."\n\n";$strBody = $strBody ."Postage rate is ".$Postage."\n";$strBody = $strBody ."\n\nTotal : ".$currency . $Basket_total; }//end else}//end else // set up mail details$mail_to = "[email protected]";//[email protected]$mail_from = stripslashes($Customer_Email);$mail_subject = "Order Confirmation";$mail_headers = "FROM: $mail_from\r\n";//added additional recipient$mail_body = $strBody; //create mail footer message$mail_footer = "\n\nText here"; //concatinate mail_body and mail_footer$mail_body = $mail_body . $mail_footer;// send mailif (mail($mail_to, $mail_subject, $mail_body, $mail_headers)) {//echo ("<p>Message sent</p>");} else {echo ("<p>Error On Sending Mail</p>");}?> Link to comment https://forums.phpfreaks.com/topic/291483-php-script-sending-duplicates-of-an-email/ Share on other sites More sharing options...
QuickOldCar Posted October 8, 2014 Share Posted October 8, 2014 I don't see anything that empties the basket once an order was placed. A user may be bookmarking or refreshing the page and revisiting it again. Link to comment https://forums.phpfreaks.com/topic/291483-php-script-sending-duplicates-of-an-email/#findComment-1493009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.