adamjnz Posted April 13, 2006 Share Posted April 13, 2006 Hey,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] Quote Link to comment Share on other sites More sharing options...
adamjnz Posted April 13, 2006 Author Share Posted April 13, 2006 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. Quote Link to comment Share on other sites More sharing options...
caraldur Posted April 13, 2006 Share Posted April 13, 2006 Could you post your code so we can have a look at it? Quote Link to comment Share on other sites More sharing options...
adamjnz Posted April 14, 2006 Author Share Posted April 14, 2006 [!--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?[/quote]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][code]<?phpmysql_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);?> <?php 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"; 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"] == "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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.