gavin1512 Posted March 10, 2008 Share Posted March 10, 2008 Good Morning, I am working on a basic internal order system with my SQL database backbone. The problem I am having is when writing from my array to the database. In the basket page it displays all items added to the basket array, and next to each item is a textbox to enter the quantity, when writing to the database it on takes the value in the last quantity box and inserts that value for all products. Here is my code for writing to the database: <?php session_start(); require "connect.php"; $quantity = $_GET['quantity']; $username = $_SESSION['username']; $order = $username.date("d/m/y : H:i:s", time()); $query = "insert into orders values ('".$order."','".$username."','pending approval','".date("d-M-Y")."')"; $result = mysql_query($query, $connection) or die (mysql_error()); $orderid = mysql_insert_id($connection); foreach($_SESSION['order'] as $key => $product) { $query = "insert into productorder values ('".$order."','".$_SESSION['order'][$key]['productnumber']."','".$quantity."', 'pending approval','".$_SESSION['order'][$key]['price']."')"; $result = mysql_query($query, $connection) or die ("Unable to perfom query<br>$query"); } unset($_SESSION['order']); $message3 = "Your Order has been sent to your manager for approval"; header("Location: productsearch.php?var=productnumber&message3=$message3"); exit(); ?> I not sure if I need a foreach loop to insert the quantity or the box needs to be renamed to include the $key or if it can be related to the productnumber field 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.