Hi, I have a form that processes purchased items. In essense there is money in a members account and they can purchase items. Everything works, the database gets updated, etc. But now I want to print what a member just purchased on the same page that processes the information. I can get all of the records from that member, but can't figure out how to get just the items that are updating/inserting at that very moment. I want to be able to view like this...
Name: Barbara Doe
Account Number: 123456
Date: November 30, 2005
Items Purchased:
Product Name: Widgets
Product Cost: $1.00
Quantity: 3
Total: $3.00
Product Name: Gadgets
Product Cost: $3.00
Quantity: 2
Total: $6.00
Product Name: Gobbles
Product Cost: $1.00
Quantity: 2
Total: $1.00
Amount Now on Record: $354.44
page1.php, the members account number is entered.
page2.php, shows the member how much money they have on record, they can view all of their purchases to date, and, if they want to purchase more items, they can select how many items they want to purchase, which goes to page3.php
page3.php then lists how ever many list menus of product based on how many items they selected in page2.php. here is the code for listing the items.
<?php
$productList = array();
$sql = "SELECT product_id, product_name FROM product_tbl ORDER BY product_name";
$res = mysql_query($sql);
while (list($code, $product) = mysql_fetch_row($res))
{
$productList[$code] = $product;
}
for ($i = 0; $i < $numProducts; $i++){
echo "<select name='product$i'>";
echo "<option value=''> - select product - </option>";
foreach($productList as $code => $product){
echo "<option value='$code'> $product </option>";
}
echo '</select>';
echo "Quantity <input type='text' name='qty$i' size='3'><BR>";
}
?>
page4.php processes their purchase, and it is here that I want to list their purchase, but don't know how to do this.
<?php require_once('founders_conn.php');
$conn = db_connect();
if (!$conn)
return 'Could not connect to database server - please try later.';
$employee = $_POST["employee_name"];
$accountNumber = $_POST['account_number'];
$firstName = $_POST["first_name"];
$lastName = $_POST["last_name"];
$customerId=$_POST['customer_id'];
$loop = count($_POST) / 2;
for ($i = 0; $i < $loop; $i++) {
if($_POST["product$i"]) $product[$i]["name"] = $_POST["product$i"];
}
for ($i = 0; $i < $loop; $i++) {
if ($_POST["qty$i"]) $product[$i]["quantity"] = $_POST["qty$i"];
}
$item = array();
foreach ($product as $item) {
$name = $item["name"];
$no = $item["quantity"];
$row = mysql_fetch_array(mysql_query("SELECT * FROM product_tbl WHERE product_id = '$name'"));
$item["cost"] = $row["product_cost"];
$item["totalcost"] = $item["cost"] * $no;
$totalcost = $item["totalcost"];
$query = mysql_query("SELECT * FROM customers_tbl WHERE customer_id='$customerId'");
$row = mysql_fetch_array($query);
$max = $row["amount_on_record"];
if ($max < $totalcost) { print "Not enough funds to make this purchase"; exit(); }
$query = mysql_query("UPDATE customers_tbl SET `amount_on_record` = `amount_on_record` - $totalcost WHERE customer_id = '$customerId'");
$query = mysql_query("INSERT INTO purchases_tbl (`purchase_id`, `customer_id`, `purchase_date`, `product_id`, `quantity`, `total_cost`) VALUES (NULL, '$customerId',NOW(), '$name', '$no', '$totalcost')");
}
?>
I have tried so many things and haven't even come close to finding the results I am looking for. Does anyone know what I need to do to get a list of what was just purchased?
thanks