Jump to content


This topic is now archived and is closed to further replies.


Some help with multiple MySQL inserts please (Dreamweaver)

Recommended Posts


I am doing an customer order site up and I am trying to store the order details in a MySQL Database. I am doing the site in dreamweaver.

I have a table called 'Orders' which stores the order number and the total and date and a table called 'Order_Products' which stores the details of the products on the orders. It has an orderID feild which matches the details with the record in the 'Orders' table.

What I am struggling with is getting it to store the details of each line of the order. I can get it to store the first line fine. I tried using the code from dreamweavers 'Repeat Reigion' featute but all I am getting is error messages.

Am I going about this the right way?

I have posted a copy of the PHP file so you can have a look at my code at:

[a href=\"http://www.adamjobbins.com/code/process_order.zip\" target=\"_blank\"]http://www.adamjobbins.com/code/process_order.zip[/a]

Share this post

Link to post
Share on other sites
I have been doing some extensive googling and have found some references to using a do...while approach to this, which is what I have been trying to do. I would really appreciate some help on this.

Share this post

Link to post
Share on other sites
[!--quoteo(post=364372:date=Apr 14 2006, 12:38 AM:name=caraldur)--][div class=\'quotetop\']QUOTE(caraldur @ Apr 14 2006, 12:38 AM) [snapback]364372[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Could you post your code so we can have a look at it?

Full PHP File avalible here: [a href=\"http://www.adamjobbins.com/code/process_order.zip\" target=\"_blank\"]http://www.adamjobbins.com/code/process_order.zip[/a]

mysql_select_db($database_ppl_frontend, $ppl_frontend);
$query_admin = "SELECT * FROM ppl_admin";
$admin = mysql_query($query_admin, $ppl_frontend) or die(mysql_error());
$row_admin = mysql_fetch_assoc($admin);
$totalRows_admin = mysql_num_rows($admin);

mysql_select_db($database_ppl_frontend, $ppl_frontend);
$query_products = "SELECT * FROM ppl_products";
$products = mysql_query($query_products, $ppl_frontend) or die(mysql_error());
$row_products = mysql_fetch_assoc($products);
$totalRows_products = mysql_num_rows($products);

mysql_select_db($database_ppl_frontend, $ppl_frontend);
$query_orders = "SELECT * FROM ppl_orders ORDER BY orderID DESC";
$orders = mysql_query($query_orders, $ppl_frontend) or die(mysql_error());
$row_orders = mysql_fetch_assoc($orders);
$totalRows_orders = mysql_num_rows($orders);
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  { ?>
  <?php do {
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
$product = $row_products['productID'];

$product_qty0 = "qty" . $product;
$product_qty = $_POST[$product_qty0];

$product_total0 = "total" . $product;
$product_total = $_POST[$product_total0];

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  return $theValue;

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "Order")) {
  $insertSQL = sprintf("INSERT INTO ppl_order_products (orderID, productID, product_quantity, product_total) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['orderID'], "int"),
                       GetSQLValueString($product, "int"),
                       GetSQLValueString($product_qty, "int"),
                       GetSQLValueString($product_total, "int"));

  mysql_select_db($database_ppl_frontend, $ppl_frontend);
  $Result1 = mysql_query($insertSQL, $ppl_frontend) or die(mysql_error());
} while ($row_products = mysql_fetch_assoc($products)); ?> <?php } ?>[/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.