Jump to content

Recommended Posts

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

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.