shop cart
束建章
2023-12-01
<?php
session_start();
$shop = $_SESSION['shop'];
if(!$shop)
{
$shop = array();
}
if($_POST['Submit'])
{
$good_id = $_POST['good_id'];
$good_num = $_POST['good_num'];
if($shop[$good_id])
{
$shop[$good_id] += $good_num;
}
else
{
$shop[$good_id] = $good_num;
}
$_SESSION['shop'] = $shop;
foreach($shop as $key => $val){
echo "编号是:".$key.",数量是".$val."<Br>";
}
}
?>
<form name="Form1" method="post" action="">
<input type="text" name="good_id">
<input type="text" name="good_num">
<input type="submit" name="Submit" value="提交">
</form>