solution Posted May 23, 2011 Share Posted May 23, 2011 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'])."'"); Quote Link to comment https://forums.phpfreaks.com/topic/237167-how-to-prevent-double-entry-inserting-in-mysql/ Share on other sites More sharing options...
Pikachu2000 Posted May 23, 2011 Share Posted May 23, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/237167-how-to-prevent-double-entry-inserting-in-mysql/#findComment-1218905 Share on other sites More sharing options...
solution Posted May 23, 2011 Author Share Posted May 23, 2011 OH OK, got it, do you have any solution for my problem ? Quote Link to comment https://forums.phpfreaks.com/topic/237167-how-to-prevent-double-entry-inserting-in-mysql/#findComment-1218909 Share on other sites More sharing options...
Zurev Posted May 23, 2011 Share Posted May 23, 2011 Why not check for a row with the same values, if it exists, don't insert the row. Otherwise, insert it. Quote Link to comment https://forums.phpfreaks.com/topic/237167-how-to-prevent-double-entry-inserting-in-mysql/#findComment-1218911 Share on other sites More sharing options...
solution Posted May 23, 2011 Author Share Posted May 23, 2011 thats a Child play "Zurev" Actually its inserting with primary key and Key is just incrementing all the way.. So there is no way to check..it happening accidently.. Quote Link to comment https://forums.phpfreaks.com/topic/237167-how-to-prevent-double-entry-inserting-in-mysql/#findComment-1218912 Share on other sites More sharing options...
Pikachu2000 Posted May 23, 2011 Share Posted May 23, 2011 No field in the database, other than the primary key, is a unique value? There's no transaction ID, authorization number, or anything like that? Quote Link to comment https://forums.phpfreaks.com/topic/237167-how-to-prevent-double-entry-inserting-in-mysql/#findComment-1218915 Share on other sites More sharing options...
Zurev Posted May 23, 2011 Share Posted May 23, 2011 Checking if an already existing row is in the database before inserting an identical one is child play? Pft. Quote Link to comment https://forums.phpfreaks.com/topic/237167-how-to-prevent-double-entry-inserting-in-mysql/#findComment-1218916 Share on other sites More sharing options...
solution Posted May 23, 2011 Author Share Posted May 23, 2011 yep, there is one more unique field called : transaction ID but everytime it is inserting into next row, ....transaction ID is unique but generating and inserting into new row you understand what I mean ? Quote Link to comment https://forums.phpfreaks.com/topic/237167-how-to-prevent-double-entry-inserting-in-mysql/#findComment-1218917 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.