该数据来自POST形式,这个想法是简单地添加时增加了一个新的产品更行。PHP:SESSION数据没有被存储
的电流输出为:
l. Banana 3 units: 150
请看看到脚本(特别foreach循环):
<?php
session_start();
//Getting the list
$list= $_SESSION['list'];
//stock
$products = array(
'Pineaple' => 500, 'Banana' => 50, 'Mango' => 150,
'Milk' => 500, 'Coffe' => 1200, 'Butter' => 300,
'Bread' => 450, 'Juice' => 780, 'Peanuts' => 800,
'Yogurt' => 450, 'Beer' => 550, 'Wine' => 2500,
);
//Saving the stuff
$_SESSION['list'] = array(
'item' => ($_POST['product']),
'quantity' => ($_POST['quantity']),
'code' => ($_POST['code']),
);
//price
$price = $products[($_SESSION['list']['item'])] * $_SESSION['list']['quantity'];
$_SESSION['list']['price'] = $price;
//listing
echo "<b>SHOPPIGN LIST</b></br>";
foreach($_SESSION as $key => $item)
{
echo $key[''], '. ', $item['item'], ' ', $item['quantity'], ' units: ', $item['price'];
}
//Recycling list
$_SESSION['list'] = $list;
echo "</br> <a href='index.html'>Return to index</a> </br>";
//Printing session
var_dump($_SESSION);
?>
会话保存为POST,但它似乎保持覆盖与一个新的POST数据.e.g。上//保存填充部分 – tradyblix 2011-04-30 00:09:25
什么是输出应该是什么?这是一个问题网站,它有助于将您的帖子形成简明的问题。 – 2011-04-30 00:09:38