Jump to content

Linking Text box to primary key


gavin1512

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/95371-linking-text-box-to-primary-key/
Share on other sites

Archived

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

×
×
  • Create New...

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.