Multiple Insert Record (Dreamweaver PHP)
Page 1, 2, 3, 4.
Checking the Code
The DW php code generated to insert the above three records (the final insert having the redirect url) looks a little along these lines:
<?php require_once('../../Connections/yourConnFile.php'); ?>
<?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"] == "mInsert")) {
$insertSQL = sprintf("INSERT INTO mminsert (rec1, rec2, dateTime) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['r1v1'], "text"),
GetSQLValueString($_POST['r1v2'], "text"),
GetSQLValueString($_POST['now'], "date"));
mysql_select_db($database_v2Conn, $v2Conn);
$Result1 = mysql_query($insertSQL, $v2Conn) or die(mysql_error());
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "mInsert")) {
$insertSQL = sprintf("INSERT INTO mminsert (rec1, rec2, dateTime) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['r2v1'], "text"),
GetSQLValueString($_POST['r2v2'], "text"),
GetSQLValueString($_POST['now'], "date"));
mysql_select_db($database_v2Conn, $v2Conn);
$Result1 = mysql_query($insertSQL, $v2Conn) or die(mysql_error());
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "mInsert")) {
$insertSQL = sprintf("INSERT INTO mminsert (rec1, rec2, dateTime) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['r3v1'], "text"),
GetSQLValueString($_POST['r3v2'], "text"),
GetSQLValueString($_POST['now'], "date"));
mysql_select_db($database_v2Conn, $v2Conn);
$Result1 = mysql_query($insertSQL, $v2Conn) or die(mysql_error());
$insertGoTo = "#";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
... NEXT :: Page 1, 2, 3, 4.