close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Multiple Insert Before Page Load

Thread began 10/29/2010 12:44 pm by dan361748 | Last modified 10/29/2010 3:31 pm by Jason Byrnes | 690 views | 5 replies |

dan361748

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!

Sign in to reply to this post

Jason ByrnesWebAssist

the multiple insert behavior is expecting form input that is not available on page load, the form input information is only available when the form on your page submits, you would be able to do this on page load.

Sign in to reply to this post

dan361748

Thanks Jason

I'm kind of struggling with the sequence on how to do this. Could you give me your advice at a high level?

Here's what I'm trying to do:

I have populated a temporary table with user ticket information (name, email address etc). The key to the table is the user's session id. The user enters this data on a form that comes up directly before the checkout page.

On the checkout_success page the system copies the tickets_temp table records to the ticketdetails table inserting the orderid received on the checkout_success page.

I have most of the above working, but the insert many behaviour won't work unless I put the tickets_temp table data into a repeat selection form. I don't want the user to have to click and submit a form - I just want those records to automatically be inserted on reaching the page. I intend on setting up a delete records behaviour to clear out the tickets_temp table at the end.

Should I use the insert many behaviour or is there another way to do this?

Many thanks - again.
Dan

Sign in to reply to this post

Jason ByrnesWebAssist

no, not an automated way to do this, you need to write the php code to loop through the temporary table contents and insert the data into the other table.

This will require hand coding to accomplish, the extensions will not be able to automate this for you.

Sign in to reply to this post

dan361748

Ok thank you for taking a look.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...