最近初學php...鬱悶死了..用的是phpdesigner
看著那錯漏百出的教材..我都無語了..一下是..複製教材一個實例的內容..一個類
<?php
class Cart
{
var $sum=0; // 目前购物车上的商品数量
var $items; // 购物车的商品
// 增加购物车上的商品
function add_item ($goods_name)
{
$this->sum++;
$this->items[$this->sum] = $goods_name;
} // 显示购物车上的商品
function show_item ()
{
for($i=0;$i<$this->sum;$i++)
{
echo $this->items[$i+1]."<br>";
}
}
}
?>
主php
<?php
include "car.php";
$car = new Cart;
if (!empty($_POST["Submit"]))
{echo "a";
/* for($j=0;$j<count($goods);$j++)
{
$car->add_item($goods[$j]);
}*/
?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>无标题文件</title>
</head><body>
<table width="100%" border="1">
<tr>
<td width="25%" rowspan="2"><form name="form1" method="post" action="">
<p>
<input name="goods[]" type="checkbox" id="goods" value="CPU">
CPU</p>
<p>
<input name="goods[]" type="checkbox" id="goods" value="主板"> 主板</p>
<p>
<input name="goods[]" type="checkbox" id="goods" value="内存"> 内存</p>
<p>
<input type="checkbox" name="goods[]" value="键盘"> 键盘</p>
<p>
<input type="checkbox" name="goods[]" value="鼠标"> 鼠标</p>
<p>
<input type="submit" name="Submit" value="放入购物车"> </p>
</form></td>
<td width="75%"><div align="center">购物车内的商品</div></td>
</tr>
<tr>
<td>
<?php
if ($car->sum==0)
{
echo "购物车中尚无商品";
}else
{
$car->show_item();
}
?>
</td>
</tr>
</table>
</body>
</html>感覺傳不進去吖..哪裡有問題..求解
看著那錯漏百出的教材..我都無語了..一下是..複製教材一個實例的內容..一個類
<?php
class Cart
{
var $sum=0; // 目前购物车上的商品数量
var $items; // 购物车的商品
// 增加购物车上的商品
function add_item ($goods_name)
{
$this->sum++;
$this->items[$this->sum] = $goods_name;
} // 显示购物车上的商品
function show_item ()
{
for($i=0;$i<$this->sum;$i++)
{
echo $this->items[$i+1]."<br>";
}
}
}
?>
主php
<?php
include "car.php";
$car = new Cart;
if (!empty($_POST["Submit"]))
{echo "a";
/* for($j=0;$j<count($goods);$j++)
{
$car->add_item($goods[$j]);
}*/
?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>无标题文件</title>
</head><body>
<table width="100%" border="1">
<tr>
<td width="25%" rowspan="2"><form name="form1" method="post" action="">
<p>
<input name="goods[]" type="checkbox" id="goods" value="CPU">
CPU</p>
<p>
<input name="goods[]" type="checkbox" id="goods" value="主板"> 主板</p>
<p>
<input name="goods[]" type="checkbox" id="goods" value="内存"> 内存</p>
<p>
<input type="checkbox" name="goods[]" value="键盘"> 键盘</p>
<p>
<input type="checkbox" name="goods[]" value="鼠标"> 鼠标</p>
<p>
<input type="submit" name="Submit" value="放入购物车"> </p>
</form></td>
<td width="75%"><div align="center">购物车内的商品</div></td>
</tr>
<tr>
<td>
<?php
if ($car->sum==0)
{
echo "购物车中尚无商品";
}else
{
$car->show_item();
}
?>
</td>
</tr>
</table>
</body>
</html>感覺傳不進去吖..哪裡有問題..求解
if (!empty($_POST["Submit"]))
{echo "a";
/* for($j=0;$j<count($goods);$j++)
{
$car->add_item($goods[$j]);
}*/
}//少了个大括号
if (isset($_POST["Submit"]))
{
$goods=$_POST['goods'];//接收表单的值
for($j=0;$j<count($goods);$j++)
{
$car->add_item($goods[$j]);
}
}