PHP: Make variables into SESSION? -


i'm working in assigment , want save data session can modified user(as primitive shopping cart), need light in here.

a) information comes post form.

b) output should this:

shoping list 1. coffe 5 units, 6 usd. 2. banana 3 units, 3 usd. 3. etc (the list can infinite) 

c) current code, can see there no session. , need user able add more items.

 <?php  //variables $item= $_post['item']; $quantity= $_post['quantity']; $code= $_post['code'];   //list $articulos = 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 index echo "</br> <a href='index.html'>back index</a>";   ?> 

$_session["foo"] = "bar"; 

also make sure call session_start() before any output document. can't stress enough. i'm talking before doctype deceleration.

then should able anywhere afterwards do..

echo $_session["foo"]; // output: bar $_session["foo"] = "new bar"; $_session["new foo"] = $_session["foo"]; 

and

$_session["items"] = array("pants", "hat"); array_push($_session["items"], "shirt"); 

etc.


Comments