|
<? Php
//
// Add_item.php:
// Add an item to the shopping cart.
//
Session_start ();
If (session_is_registered ('cart ')){
Session_register ('cart ');
}
Require 'Lib. inc. Php'; // LoadProducts ()
LoadProducts (); // Load products in $ master_products_list
// Make $ curr_product global
$ Curr_product = array ();
// Loop through all the products and pull up the product
// That we are interested in
Foreach ($ master_products_list as $ prod_id => $ product ){
If (trim ($ prod_id) = trim ($ _ GET [id]) {
$ Curr_product = $ product;
}
}
// Register our session
// Session_register ('cart ');
// If (session_is_registered ('cart') echo "registered ";
If ($ _ POST [ordered]) {// If they have chosen the product
Array_push ($ _ SESSION [cart] [products], array (trim ($ _ POST [id]), $ _ POST [quantity]);
$ _ SESSION [cart] [num_items] + =$ _ POST [quantity];
}
?>
<Html>
<Head>
<Title>
<? Php if ($ _ POST [ordered]) {?>
Added <? Php echo $ curr_product [name];?> To your shopping basket
<? Php} else {?>
Add <? Php echo $ curr_product [name];?> To your shopping basket
<? Php }?>
</Title>
</Head>
<Body>
<? Php if ($ _ POST [ordered]) {?>
<H1> <? Php echo $ curr_product [name];?>
Successfully added to the shopping basket
<A href = "cart. php"> Return to the </a> item list page.
<? Php} else {?>
<H1> add <? Php echo $ curr_product [name];?> To your shopping basket
<Form action = "<? Php echo $ PHP_SELF;?> "Method =" post ">
Product Name: <? Php echo $ curr_product [name];?>
<Br>
Product description: <? Php echo $ curr_product [desc];?>
<Br>
Unit Price: RMB <? Php echo $ curr_product [price];?>
<Br>
Item quantity: <input type = "text" size = "7" name = "quantity">
<Input type = "hidden" name = "id" value = "<? Php echo $ _ GET [id];?> ">
<Input type = "hidden" name = "ordered" value = "1">
<Input type = "submit" value = "Add to shopping bar">
</Form>
<? Php }?>
</Body>
</Html> |