Jump to content

Duplicate records from Ajax call.


stockton

Recommended Posts

I use the following to call Ajax :-

 

<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); 

  }

 

T4.php looks like:-

<?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

 

?>

 

The problem is that I end up with two identical records in the TicketsIssued table.

Note that these records are identical, not one for "Slots" and one for "Tables".

Suggestions on what I have done wrong would be gratefully received.

 

Link to comment
https://forums.phpfreaks.com/topic/44786-duplicate-records-from-ajax-call/
Share on other sites

  • 2 weeks later...

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.