PHP Classes

File: db_cart_stock_confirm.php

Recommend this page to a friend!
  Classes of Olaf Lederer  >  DB Cart Class  >  db_cart_stock_confirm.php  >  Download  
File: db_cart_stock_confirm.php
Role: Application script
Content type: text/plain
Description: an example that shows a confirmation and updates the stock value
Class: DB Cart Class
Manage a shopping cart stored in a MySQL database
Author: By
Last change:
Date: 17 years ago
Size: 2,686 bytes


Class file image Download

// create a new cart object
$myConfirm = new db_stock_cart($_SESSION['custom_num']);

if (
$myConfirm->get_number_of_records() == 0) header("Location: ".PROD_IDX); // redirect if there is no data (anymore)

// the next methods are only used to store the data into arrays and variables

// request the last version of the shipment information

// at least modify the stock amount in the product tabel and set the last modified data
$sql_errors = 0;
foreach (
$myConfirm->order_array as $val) {
$update_stock = sprintf("UPDATE db_cart_stock_article_example SET amount = amount - %d, last_buy = NOW() WHERE art_no = '%s'", $val['quantity'], $val['product_id']);
    if (!
mysql_query($update_stock)) {
if (
$sql_errors == 0) {
} else {
$myConfirm->error = $myConfirm->messages(1);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>DB_cart example page</title>
<style type="text/css">
table {
th {
    padding:5px 0 0 10px;
    border-bottom:1px solid #666666;
td {
    padding:5px 10px;

<h2>DB_cart &quot;confirmation&quot; expample</h2>
<p>This page is an example to show the processed order.</p>
<p style="color:#FF0000;font-weight:bold;margin:10px 0;"><?php echo $myConfirm->error; ?></p>
<h3>Your order:</h3>
    <th>Art. no.</th>
  <?php foreach ($myConfirm->order_array as $val) { ?>
    <td><?php echo $val['product_id']; ?></td>
    <td><?php echo $val['product_name']; ?></td>
    <td align="center"><?php echo $val['quantity']; ?></td>
    <td align="right"><?php echo $myConfirm->format_value($val['price']); ?></td>
    <td align="right"><?php echo $myConfirm->format_value($val['price'] * $val['quantity']); ?></td>
  <?php } // end foreach loop ?>
<h3>will be shipped to:</h3>
echo $myConfirm->ship_name."<br>";
$myConfirm->ship_pc." ".$myConfirm->ship_city."<br>";
<?php echo ($myConfirm->ship_msg != "") ? "<p><b>The message:</b><br>".nl2br($myConfirm->ship_msg)."</p>" : ""; ?>
<p><a href="./<?php echo PROD_IDX; ?>">&gt;&gt; Back to main... </a></p>

For more information send a message to info at phpclasses dot org.