I want to save this data into a SESSION so it can be modified by the user(as a primitive shopping cart), but I need some light in here.
A) The information comes from a POST form.
B) The output should look like this:
SHOPING LIST
1. Coffe 5 units, 6 USD.
2. Banana 3 units, 3 USD.
3. Etc (The list can be infinite)
C) This is my current code, as you can see there is no session. And I need the user to be able to add more items.
<?php
//Variables
$item= $_POST['item'];
$quantity= $_POST['quantity'];
$code= $_POST['code'];
//List
$artic开发者_StackOverflow中文版ulos = array(
'Pinaple' => 1, 'Banana' => 2, 'Aple' => 3,
'Milk' => 1, 'Coffe' => 3, 'Butter' => 1,
'Bread' => 2, 'Juice' => 1, 'Coconuts' => 1,
'Yogurt' => 2, 'Beer' => 1, 'Wine' => 6,
);
//Price
$price = $items[$item] * $quantity;
//Shoping List
echo "<b>Shopping List</b></br>";
echo "1. ".$item." ".$quantity." units".", ".$price." USD.";
//Back to index
echo "</br> <a href='index.html'>Back to Index</a>";
?>
Put session_start(); at the start of your script, you can then put anything you want into $_SESSION, including arrays of products.
$_SESSION['cart'] = $whatever_variable_you_want;
精彩评论