Jump to content

How to Prevent Double entry inserting in mysql ?


solution

Recommended Posts

Hi Friends,

 

I am suffering with very serious problem, We have a deal selling website--Problem is that when someone buy a deal , they are getting 2 vouchers on bahalf of one while they are getting charged ones only [i am using authorized.net payment gateway].

 

for some reason Entry is inserting TWICE in MYSQL but it is not happening on every purchase, it happens once in 20 purchase (for example)....

 

I have tried every possible effort but it still happens, anybody can show me helping hand please ?

 

this is my partial code where I am inserting the voucher info :

 

for($i=0; $i<$_SESSION['quHidden']; $i++):
   
      if($_SESSION['RecName'][$i]!=''):$IsGist="t";$GRName=$_SESSION['RecName'][$i];else:$IsGist="f";$GRName="";endif;
$coupon_code=str_makerand("12", "12", "false", "false", "false");
$NCCod="#".$coupon_code;

$download_path="dealcoupon.php?id=".$sql_coupon['deal_id']."&CRANCode=".$coupon_code; 
$DLContent[]="<a href=\"".$download_path."\" target=\"_blank\" style=\"font-family: Helvetica,Arial,sans-serif; color: rgb(9, 129, 190);font-size: 14px;\">Download Voucher: ".$NCCod."</a>";

mysql_query("INSERT INTO `tbl_purchase` ( `fld_buyerid` , `fld_dealid` , `fld_amount` , `fld_purchaseid`, `fld_subdate`, `fld_expdate`, `fld_quantity`, `fld_cardno`, `isGift`, `fld_RecName`) 
VALUES (
'".$_SESSION['usr_id']."', '".$sql_coupon['deal_id']."', '".$sql_coupon['deal_price']."', '$NCCod', '".time()."', '".$sql_coupon[deal_edate]."', '1', '".$_SESSION['x_card_num']."','".$IsGist."','".$GRName."')");
$CoupanArr[]=$NCCod;

endfor;
//---------------------------------------------------------------------
mysql_query("insert into tbl_vouemails set fld_did='".$sql_coupon['deal_id']."', fld_uid='".$_SESSION['usr_id']."', fld_voucher='".implode(",",$CoupanArr)."', fld_etime='".getPATime($sql_coupon[deal_edate])."', fld_subdate='".time()."', fld_VReceiver='".implode(",",$_SESSION['RecName'])."'");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.