PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?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();
?>
And currently the text box is just declared as <input name="quantity" type="text">
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
Not sure I follow 100% -- if you have multiple form fields all named quantity and you submit your products to database, the quantity value in the last FORM should be the one which all your products inherit, is this correct?
The basket displays all the products in the basket array, and for each product a quantity box is displayed. The user can then enter how many of each product they require next to each product, then will click the submit button to confirm the order, writing it to the database
The problem I am faced with is that the GET statement I am using is only getting the value from the final textbox and inserting that for every value, instead of getting values from all the textboxes
I did try to create a foreach loop to get all the individual values and insert them into the array but not sure if it was my coding or if this just was not feasible
The problem I am faced with is that the GET statement I am using is only getting the value from the final textbox and inserting that for every value, instead of getting values from all the textboxes
Sorry I am a fairly basic using doing this as part of a university project
I have tried both methods but entirely sure on how index each, is it possible to relate it back to the primary key? or is it by its position in the array