Duplicate record insertion

Ask a Question related to Dreamweaver AppDev, Design and Development.

  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. Similar Questions and Discussions

    1. Using the Record Insertion Application Object
      I am using the Record Insertion Application Object on a CF page. I have it updating a simple Access Database. My Primary Key is the ID Field and its...
    2. Need help for Record Insertion
      I am struggeling with the exact same problem. Have you solved it yet? Anyone else have any suggestions? Thanks!
    3. Record Insertion Form causes multiple entries
      I'm using DMX with PHP / MySQL and the Record Insertion Form from the Application tab. I test the form and check the database only to find that...
    4. Record insertion form trouble
      Hey all: When trying to use the "record insertion form" function to set up a form for a mysql database I get this error: Line 4434 file macintosh...
    5. preventing duplicate row insertion from asp.net app
      Data is stored in SQL Server 2000. One table is Person another Item. Each row in the Person table may have associated with it several rows in the...
  3. #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" <webforumsuser@macromedia.com> wrote in message
    news:d1fvj7$k7m$1@forums.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

Posting Permissions

  • You may not post new threads
  • You may 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