Professional Web Applications Themes

Duplicate record insertion - Dreamweaver AppDev

Hi there, I have a DW insert record behaviour on a php page. If the user clicks Submit quickly multiple times, I end up with duplicate records. Any suggestions on how to modify the insert record behaviour to prevent this? Thanks, Tim <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ...

  1. #1

    Default Duplicate record insertion

    Hi there, I have a DW insert record behaviour on a php page. If the user
    clicks Submit quickly multiple times, I end up with duplicate records. Any
    suggestions on how to modify the insert record behaviour to prevent this?
    Thanks, Tim

    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
    $theNotDefinedValue = "")
    {
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
    "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
    $insertSQL = sprintf("INSERT INTO tblaccessories (txtProductCode,
    txtProductDescription, txtVendorCode, curPurchaseCost, curSellingPrice,
    dteCreationDate, txtProductLine, txtStore) VALUES (%s, %s, %s, %s, %s, %s, %s,
    %s)",
    GetSQLValueString($ProductCode, "text"),
    GetSQLValueString($_POST['Description'], "text"),
    GetSQLValueString($_POST['VendorCode'], "text"),
    GetSQLValueString($_POST['PurchaseCost'], "text"),
    GetSQLValueString($_POST['SellingPrice'], "text"),
    GetSQLValueString(date('ymdhis', time()), "date"),
    GetSQLValueString("ACC", "text"),
    GetSQLValueString($_SESSION['MM_Username'], "text"));

    mysql_select_db($database_SKUWizard, $SKUWizard);
    $Result1 = mysql_query($insertSQL, $SKUWizard) or die(mysql_error());

    $insertGoTo = "Accessory_Added.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    }
    header(sprintf("Location: %s", $insertGoTo));
    }
    ?>

    force4ormore Guest

  2. #2

    Default Re: Duplicate record insertion


    setting a session variable, that doesn't let the user post it twice...

    i.e. (pseudo code, I don't know PHP)

    script
    test for session variable, if it doesn't exist
    Create SessionVariable
    do insert
    end.

    problem is that it won't allow them to insert another record...

    in electronics its called de-bouncing, I have no idea if there is a special
    procedure in code for this...


    "force4ormore" <webforumsusermacromedia.com> wrote in message
    news:d1fvj7$k7m$1forums.macromedia.com...
    > Hi there, I have a DW insert record behaviour on a php page. If the user
    > clicks Submit quickly multiple times, I end up with duplicate records. Any
    > suggestions on how to modify the insert record behaviour to prevent this?
    > Thanks, Tim
    >
    > <?php
    > function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
    > $theNotDefinedValue = "")
    > {
    > $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) :
    $theValue;
    >
    > switch ($theType) {
    > case "text":
    > $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    > break;
    > case "long":
    > case "int":
    > $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    > break;
    > case "double":
    > $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
    > "NULL";
    > break;
    > case "date":
    > $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    > break;
    > case "defined":
    > $theValue = ($theValue != "") ? $theDefinedValue :
    $theNotDefinedValue;
    > break;
    > }
    > return $theValue;
    > }
    >
    > $editFormAction = $_SERVER['PHP_SELF'];
    > if (isset($_SERVER['QUERY_STRING'])) {
    > $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    > }
    >
    > if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
    > $insertSQL = sprintf("INSERT INTO tblaccessories (txtProductCode,
    > txtProductDescription, txtVendorCode, curPurchaseCost, curSellingPrice,
    > dteCreationDate, txtProductLine, txtStore) VALUES (%s, %s, %s, %s, %s, %s,
    %s,
    > %s)",
    > GetSQLValueString($ProductCode, "text"),
    > GetSQLValueString($_POST['Description'], "text"),
    > GetSQLValueString($_POST['VendorCode'], "text"),
    > GetSQLValueString($_POST['PurchaseCost'], "text"),
    > GetSQLValueString($_POST['SellingPrice'], "text"),
    > GetSQLValueString(date('ymdhis', time()), "date"),
    > GetSQLValueString("ACC", "text"),
    > GetSQLValueString($_SESSION['MM_Username'],
    "text"));
    >
    > mysql_select_db($database_SKUWizard, $SKUWizard);
    > $Result1 = mysql_query($insertSQL, $SKUWizard) or die(mysql_error());
    >
    > $insertGoTo = "Accessory_Added.php";
    > if (isset($_SERVER['QUERY_STRING'])) {
    > $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    > $insertGoTo .= $_SERVER['QUERY_STRING'];
    > }
    > header(sprintf("Location: %s", $insertGoTo));
    > }
    > ?>
    >

    gerry - dergal Guest

Similar Threads

  1. Using the Record Insertion Application Object
    By cboschert78 in forum Macromedia ColdFusion
    Replies: 0
    Last Post: May 20th, 01:08 PM
  2. Need help for Record Insertion
    By steinp in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 17th, 08:14 AM
  3. Record Insertion Form causes multiple entries
    By BarryCrandall in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 15th, 10:41 PM
  4. Record insertion form trouble
    By BAlice in forum Dreamweaver AppDev
    Replies: 0
    Last Post: March 4th, 04:08 PM
  5. preventing duplicate row insertion from asp.net app
    By aboesteanu@yahoo.com in forum ASP.NET General
    Replies: 2
    Last Post: August 11th, 07:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139