Multiple Insert Before Page Load
Hi - wondering if someone out there could give some guidance. I've been trying to figure this out for a couple of days now.
On my 'checkout-success' page I'm trying to insert multiple records to a table on page load. If I add in a submit button and bind that to the trigger of the multiple insert behavior, the records insert correctly on pressing submit. However if I bind the trigger to 'before page load' (which is what I want) the records don't insert on page load.
Here is my code at the top of the page:
<?php
//WA eCart Include
require_once("WA_eCart/eCart1_PHP.php");
?>
<?php require_once('Connections/ourhands1.php'); ?>
<?php require_once("WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php
$eCart1->GetContent();
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
?>
<?php
$_SESSION['ticketstemp'] = session_id();
$colname_ticketstemp = "-1";
if (isset($_SESSION['ticketstemp'])) {
$colname_ticketstemp = (get_magic_quotes_gpc()) ? $_SESSION['ticketstemp'] : addslashes($_SESSION['ticketstemp']);
}
mysql_select_db($database_ourhands1, $ourhands1);
$query_ticketstemp = sprintf("SELECT * FROM tickets_temp WHERE sessionid = %s", GetSQLValueString($colname_ticketstemp, "text"));
$ticketstemp = mysql_query($query_ticketstemp, $ourhands1) or die(mysql_error());
$row_ticketstemp = mysql_fetch_assoc($ticketstemp);
$totalRows_ticketstemp = mysql_num_rows($ticketstemp);
?>
<?php
// RepeatSelectionCounter_1 Initialization
$RepeatSelectionCounter_1 = 0;
$RepeatSelectionCounterBasedLooping_1 = false;
$RepeatSelectionCounter_1_Iterations = "-1";
?>
<?php
// WA DataAssist Multiple Inserts
if ("" == "") // Trigger
{
if (!session_id()) session_start();
$WA_loopedFields = array("firstname", "lastname", "nameatcamp", "yearsatcamp", "email", "areasatcamp");
$WA_connection = $ourhands1;
$WA_table = "ticketdetails";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_fieldNamesStr = "orderid|cartid|firstname|lastname|nameatcamp|yearsatcamp|emailaddress|areasatcamp";
$WA_columnTypesStr = "',none,''|none,none,NULL|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''";
$WA_insertIfNotBlank = "";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_ourhands1;
$WA_multipleInsertCounter = 0;
mysql_select_db($WA_connectionDB, $WA_connection);
while (WA_AB_checkMultiInsertLoopedFieldsExist($WA_loopedFields, $WA_multipleInsertCounter)) {
if ($WA_insertIfNotBlank == "" || WA_AB_checkLoopedFieldsNotBlank(array($WA_insertIfNotBlank), $WA_multipleInsertCounter)) {
$WA_fieldValuesStr = "".((isset($_SESSION["eCart1_OrderID"]))?$_SESSION["eCart1_OrderID"]:"") ."" . "|" . "".$eCart1->DisplayInfo("ID") ."" . "|" . "".WA_AB_getLoopedFieldValue("firstname", $WA_multipleInsertCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("lastname", $WA_multipleInsertCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("nameatcamp", $WA_multipleInsertCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("yearsatcamp", $WA_multipleInsertCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("email", $WA_multipleInsertCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("areasatcamp", $WA_multipleInsertCounter) ."";
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
}
$WA_multipleInsertCounter++;
}
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<?php
// WA eCart Redirect
if ($eCart1->redirStr != "") {
header("Location: ".$eCart1->redirStr);
}
?>
<?php
$eCart1->ClearCart();
session_regenerate_id();
?>
Many thanks for any help!