Ask a Question related to Dreamweaver AppDev, Design and Development.
-
force4ormore #1
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
-
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... -
Need help for Record Insertion
I am struggeling with the exact same problem. Have you solved it yet? Anyone else have any suggestions? Thanks! -
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... -
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... -
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... -
gerry - dergal #2
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...$theValue;> 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) :$theNotDefinedValue;>
> 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 :%s,> 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,"text"));> %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'],>
> 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



Reply With Quote

