stockton Posted March 27, 2007 Share Posted March 27, 2007 I have a php script on a server that ends up inserting duplicate records and I cannot see why. The code is as follows:- <?php // // T4.php called from T2.php to Issue tickets // Retrieve data from T2 screen and insert into TicketIssued table // require_once('includes/configuration.php'); // database connect script & the rest. DBConnect(); // Connect to Events database $Datum = date("Y-m-d H:i:s"); /* 2006-03-17 23:22:32 */ $Event = strip_tags($_GET['EventID']); $MemberNum = strip_tags($_GET['MemberNum']); $SlotsValue = strip_tags($_GET['SlotsValue']); $ValueSlots = sprintf("%d",$SlotsValue); $SlotsTurnover = strip_tags($_GET['SlotsTurnover']); $TablesValue = strip_tags($_GET['TablesValue']); $ValueTables = sprintf("%d",$TablesValue); $TablesTurnover = strip_tags($_GET['TablesTurnover']); if ($ValueSlots > 0) { $EarnType = "Slots"; $SQL = sprintf("INSERT INTO TicketsIssued (Date, EventID, MemberNumber, EarnType, NumTicketsIssued, Turnover, UserID) VALUES ('%s', '%d', '%s', '%s', '%d', '%d', '%d')", $Datum, $Event, $MemberNum, $EarnType, $SlotsValue, $SlotsTurnover, $_SESSION['UID']); $rs = mssql_query($SQL, $link); if (!$rs) echo get_sql_error($SQL, $link, $sError, $bDebug); } if ($ValueTables > 0) { $EarnType = "Tables"; $SQL = sprintf("INSERT INTO TicketsIssued (Date, EventID, MemberNumber, EarnType, NumTicketsIssued, Turnover, UserID) VALUES ('%s', '%d', '%s', '%s', '%d', '%d', '%d')", $Datum, $Event, $MemberNum, $EarnType, $TablesValue, $TablesTurnover, $_SESSION['UID']); $rs = mssql_query($SQL, $link); if (!$rs) echo get_sql_error($SQL, $link, $sError, $bDebug); } DBDisConnect(); // Disconnect from Events database // echo $SQL; ?> and it is called via Ajax with:- <input type="button" value="Issue" Onclick="sendRequest('.$IssueTickets.",".$Event.',1)"> and sendRequest looks like:- function sendRequest(Mode, Event, CardNumber) { // Call PHP script for requests if (Mode == 2) // ClientData { http.open('get', 'T3.php?EventID='+Event+'&MemberNum='+CardNumber); http.onreadystatechange = handleClientDataResponse; } else if (Mode == 3) // IssueTickets { var KaartNommer = TicketIssue.CardNumber.value; var SlotsValue = document.getElementById("SlotsValue").innerHTML; var SlotsTurnover = document.getElementById("SlotsTurnover").innerHTML; var TablesValue = document.getElementById("TablesValue").innerHTML; var TablesTurnover = document.getElementById("TablesTurnover").innerHTML; var BonusValue = document.getElementById("BonusValue").innerHTML; http.open('get', 'T4.php?EventID='+Event+'&MemberNum='+KaartNommer+'&SlotsValue='+SlotsValue+'&SlotsTurnover='+SlotsTurnover+'&TablesValue='+TablesValue+'&TablesTurnover='+TablesTurnover); http.onreadystatechange = handleIssueTicketsResponse; } http.send(null); } Suggestion as to why I end up with two records that look exactly the same would be gratefully accepted. Link to comment https://forums.phpfreaks.com/topic/44484-solved-inserting-duplicate-records/ Share on other sites More sharing options...
stockton Posted April 9, 2007 Author Share Posted April 9, 2007 I used :- ALTER TABLE table-name ADD CONSTRAINT NoDuplicates UNIQUE (Date,MemberNumber) after having read :- http://www.thescripts.com/forum/thread156807.html Link to comment https://forums.phpfreaks.com/topic/44484-solved-inserting-duplicate-records/#findComment-224839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.