logo spacer

Design Resources

mascot
spacer icon menu spacer
spacer
You are here: bulletHome > Design Resources >



Website Design Logo

Colour Key:

  • || Page Links
  • a. Site Menu
  • || Emphasis Only

 


bulletDesign Resources

Page 1, 2, 3, 4.

Polish It Off

To be posh, you can also give the variable of each SQL instance a unique name. The last bit of tidying up is to combine all insert actions into the one statement. This is done by cutting the first and second insert statements and pasting them into the last condition right after the line;

$Result1 = mysql_query($insertSQL, $v2Conn) or die(mysql_error());

Then deleting the bits left behind.

So after tidying up, all we are left with is;

<?php
require_once('../../Connections/yourConnFile.php');
mysql_select_db($database_v2Conn, $v2Conn);
// clean values for SQL
function gSQL($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
}
return $theValue;
}
// do inserts
if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {
$insertSQL1 = sprintf("INSERT INTO mminsert (rec1, rec2, dateTime) VALUES (%s, %s, %s)",
gSQL($_POST['r1v1'], "text"),
gSQL($_POST['r1v2'], "text"),
gSQL($_POST['now'], "date"));
$Result1 = mysql_query($insertSQL1, $v2Conn) or die(mysql_error());
$insertSQL2 = sprintf("INSERT INTO mminsert (rec1, rec2, dateTime) VALUES (%s, %s, %s)",
gSQL($_POST['r2v1'], "text"),
gSQL($_POST['r2v2'], "text"),
gSQL($_POST['now'], "date"));
$Result2 = mysql_query($insertSQL2, $v2Conn) or die(mysql_error());
$insertSQL3 = sprintf("INSERT INTO mminsert (rec1, rec2, dateTime) VALUES (%s, %s, %s)",
gSQL($_POST['r3v1'], "text"),
gSQL($_POST['r3v2'], "text"),
gSQL($_POST['now'], "date"));
$Result3 = mysql_query($insertSQL3, $v2Conn) or die(mysql_error());
header("Location: #recs");
}
?>

Enjoy!!

... Design Resources Index :: This Article Page 1, 2, 3, 4.

 

 

 

 

spacer spacer
Copyright © 2005 v2Media All Rights Reserved.
By using this Website, you agree with our Terms and Conditions.

www.v2media.biz contact details;
phone: +61 7 5665 8808 mobile: +61 0407 133805 email: sales@v2media.biz