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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.