下面是类的用法实例页面:
<?php
session_start();
include ("admin/config/twt_Cart.CLASS.php");
include ("admin/config/config.php");
include ("admin/config/function.php");
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>我的购物车</title>
</head>
<style>
table {
border: 0.5px solid;
}
.tbbb {
border: 0.5px solid #FFCCFF;
}
</style>
<script language="javascript">
<!--
//函数名:fucCheckNUM
//功能介绍:检查是否为大于0数字
//参数说明:要检查的数字
//返回值:1为是数字,0为不是数字
function fucCheckNUM(NUM)
{
var i,j,k,strTemp;
strTemp="0123456789.";
if ( NUM.length== 0)
return false;
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//说明有字符不是数字
return false;
}
}
//检查小数点的个数
k=0;
strTemp=".";
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j != -1)
{
//是小数点
k+=1;
}
if (k>0) return false;
}
if (NUM<=0) return false;
//说明是数字
return true;
}function checknum(num)
{
if (! fucCheckNUM(num))
{
document.frmspin.f_num.value=1;
alert("请输入大于0的下整数!");
return false;
}
}
function modifyid(id)
{
document.frmsplist.action="mycart.php?action=modify&id="+id;
document.frmsplist.submit();
}
//-->
</script>
<body>
<?
$thiscart=new twt_Cart;
$field[0]="id";
$field[1]="name";
$field[2]="num";
$field[3]="gold";
$thiscart->setfield($field);
$thiscart->setkey("id","num","gold");
if ($_GET[action]=="incart")
{
$tlist["id"]=$_POST[f_id];
$tlist["name"]=$_POST[f_name];
$tlist["num"]=$_POST[f_num];
$tlist["gold"]=$_POST[f_gold];
$thiscart->addone($tlist);
}
if ($_GET[action]=="del")
{
$thiscart->delone($_GET[id]);
}
if ($_GET[action]=="modify")
{
$thiscart->modifyone($_GET[id],$_POST["t_num_$_GET[id]"]);
}
if ($_GET[action]=="clear")
{
$thiscart->clear();
}
if ($_GET[action]=="add1")
{
$thiscart->add1($_GET[id]);
}
if ($_GET[action]=="del1")
{
$thiscart->del1($_GET[id]);
}
if($_GET[action]=='indb')
{
if ($thiscart->sp_count==0)
{ $tmpstr="alert(\"没有定购任何商品!\");
window.close();";
echo getjavascript($tmpstr);
}
else
{
$sql[0]="delete from dglist where dgl_bjid=$_SESSION[wb_bjid]";
$sql[1]="delete from dinggou where dg_uid=$_SESSION[wb_id] and dg_jid=$_SESSION[wb_bjid]";
exesql($conf_db,$sql,$db,"清空旧的商品列表出错!","echo",true,"res");
//插入定购表
$sql="insert into dinggou set dg_uid=$_SESSION[wb_id],dg_jid=$_SESSION[wb_bjid]";
exesql($conf_db,$sql,$db,"提交定单出错!","echo",true,"res");
//插入商品
$sql=array();
for ($i=0;$i<$thiscart->sp_count;$i++)
{
$sql[$i]="insert into dglist set dgl_bjid=$_SESSION[wb_bjid],dgl_pid=".$thiscart->cart[$i]["id"].",dgl_num=".$thiscart->cart[$i]["num"];
// echo $sql[$i];
}
exesql($conf_db,$sql,$db,"提交商品订单出错!","popup",true,"res");
$thiscart->clear();
$tmpstr="alert(\"操作完成,购物车已经被清空!\");
window.open(\"http://".$_SESSION[wb_sip].":5026/dg|".rawurlencode($_SESSION[wb_bjno])."| \",\"订购商品\",\"width=500 height=300 revisable=no scrollbar=yes menubar=no status=no directions=no location=no toolbar=no\");
window.close();";
echo getjavascript($tmpstr);
}
}
?>
<?php
session_start();
include ("admin/config/twt_Cart.CLASS.php");
include ("admin/config/config.php");
include ("admin/config/function.php");
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>我的购物车</title>
</head>
<style>
table {
border: 0.5px solid;
}
.tbbb {
border: 0.5px solid #FFCCFF;
}
</style>
<script language="javascript">
<!--
//函数名:fucCheckNUM
//功能介绍:检查是否为大于0数字
//参数说明:要检查的数字
//返回值:1为是数字,0为不是数字
function fucCheckNUM(NUM)
{
var i,j,k,strTemp;
strTemp="0123456789.";
if ( NUM.length== 0)
return false;
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//说明有字符不是数字
return false;
}
}
//检查小数点的个数
k=0;
strTemp=".";
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j != -1)
{
//是小数点
k+=1;
}
if (k>0) return false;
}
if (NUM<=0) return false;
//说明是数字
return true;
}function checknum(num)
{
if (! fucCheckNUM(num))
{
document.frmspin.f_num.value=1;
alert("请输入大于0的下整数!");
return false;
}
}
function modifyid(id)
{
document.frmsplist.action="mycart.php?action=modify&id="+id;
document.frmsplist.submit();
}
//-->
</script>
<body>
<?
$thiscart=new twt_Cart;
$field[0]="id";
$field[1]="name";
$field[2]="num";
$field[3]="gold";
$thiscart->setfield($field);
$thiscart->setkey("id","num","gold");
if ($_GET[action]=="incart")
{
$tlist["id"]=$_POST[f_id];
$tlist["name"]=$_POST[f_name];
$tlist["num"]=$_POST[f_num];
$tlist["gold"]=$_POST[f_gold];
$thiscart->addone($tlist);
}
if ($_GET[action]=="del")
{
$thiscart->delone($_GET[id]);
}
if ($_GET[action]=="modify")
{
$thiscart->modifyone($_GET[id],$_POST["t_num_$_GET[id]"]);
}
if ($_GET[action]=="clear")
{
$thiscart->clear();
}
if ($_GET[action]=="add1")
{
$thiscart->add1($_GET[id]);
}
if ($_GET[action]=="del1")
{
$thiscart->del1($_GET[id]);
}
if($_GET[action]=='indb')
{
if ($thiscart->sp_count==0)
{ $tmpstr="alert(\"没有定购任何商品!\");
window.close();";
echo getjavascript($tmpstr);
}
else
{
$sql[0]="delete from dglist where dgl_bjid=$_SESSION[wb_bjid]";
$sql[1]="delete from dinggou where dg_uid=$_SESSION[wb_id] and dg_jid=$_SESSION[wb_bjid]";
exesql($conf_db,$sql,$db,"清空旧的商品列表出错!","echo",true,"res");
//插入定购表
$sql="insert into dinggou set dg_uid=$_SESSION[wb_id],dg_jid=$_SESSION[wb_bjid]";
exesql($conf_db,$sql,$db,"提交定单出错!","echo",true,"res");
//插入商品
$sql=array();
for ($i=0;$i<$thiscart->sp_count;$i++)
{
$sql[$i]="insert into dglist set dgl_bjid=$_SESSION[wb_bjid],dgl_pid=".$thiscart->cart[$i]["id"].",dgl_num=".$thiscart->cart[$i]["num"];
// echo $sql[$i];
}
exesql($conf_db,$sql,$db,"提交商品订单出错!","popup",true,"res");
$thiscart->clear();
$tmpstr="alert(\"操作完成,购物车已经被清空!\");
window.open(\"http://".$_SESSION[wb_sip].":5026/dg|".rawurlencode($_SESSION[wb_bjno])."| \",\"订购商品\",\"width=500 height=300 revisable=no scrollbar=yes menubar=no status=no directions=no location=no toolbar=no\");
window.close();";
echo getjavascript($tmpstr);
}
}
?>
解决方案 »
- 这个一般怎么做?
- 下哪种eclipse
- linux 下 Mysql 数据访问量也不是很大,为什么老是死掉,要重启数据库才能访问 !
- echo 输出提示框的问题
- 求救!!!关于在php+gtk环境下开发
- 有没有办法判断客户是否禁用了FLASH显示?
- 寻找合作伙伴,一起进步并散分。
- 求大神帮我分析以下代码,我大概能读懂 80%
- 我用PHP的图形函数生成图片时,为什么中文显示为乱码?
- 我现在网站系统是dedecms,我想用Thinkphp框架开发一些自己想要的功能,但是怎么整合到一起呢,还有就是后台功能也要用tp来写?
- php5下fnmatch怎么不支持?
- 请问:为什么我的PHP文件在浏览器中显示出来的是空白啊?
</div>
<table width="503" border="1" align="center" cellpadding="0" cellspacing="1" bordercolor="#CCCCFF">
<form name="frmsplist" method="post" action="mycart.php?action=indb">
<tr>
<td colspan="2"><div align="left"><a href="mycart.php?action=clear"><img src="image/cart/clear.gif" width="79" height="17" border="0"></a></div></td>
<td colspan="3"><div align="center"></div>
<div align="right">
<table width="91" border="1" cellpadding="0" cellspacing="3" bordercolor="#FFCCFF" bgcolor="#CCCCFF">
<tr>
<td width="81" bordercolor="#FFFF00"><div align="center">
<input type="image" name="submit" src="image/cart/done.gif" border="0">
</div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td width="58"><div align="center">编号</div></td>
<td width="168"><div align="center">品名</div></td>
<td width="53"><div align="center">数量</div></td>
<td width="63"><div align="center">价格</div></td>
<td width="149"><div align="center">操作</div></td>
</tr>
<?php
for ($i=0;$i<$thiscart->sp_count;$i++)
{
?><tr>
<td><div align="center"><?php echo $i+1; ?></div></td>
<td><div align="center">
<input type="text" name="textfield" value="<?php echo $thiscart->cart[$i]["name"]; ?>" readonly>
</div></td>
<td><div align="center">
<input name="t_num_<?php echo $i; ?>" type="text" id="t_num_<?php echo $i; ?>" value="<?php echo $thiscart->cart[$i]["num"]; ?>" size=7>
</div></td>
<td><div align="right"><?php echo $thiscart->cart[$i]["gold"]; ?></div></td>
<td><div align="center"><a href="javascript:modifyid(<?php echo $i; ?>);">修改</a> <a href="mycart.php?action=add1&id=<?php echo $i; ?>">加1</a> <a href="mycart.php?action=del1&id=<?php echo $i; ?>">减1</a> <a href="mycart.php?action=del&id=<?php echo $i; ?>">删除</a> </div></td>
</tr><?php
}
?><tr>
<td colspan="2"><div align="center"> </div></td>
<td><div align="center">总额</div></td>
<td colspan="2"><div align="right"><?php echo $thiscart->sp_sumgold; ?>元
</div></td>
</tr>
</form>
</table>
<table width="503" border="0" align="center" cellpadding="6" cellspacing="0">
<tr>
<td><div align="right"><a href="#" target="_self"><img src="image/cart/goon.gif" width="79" height="17" border="0" usemap="#Map" onClick="javascript:window.close();"></a></div></td>
</tr>
</table>
<div align="center"><br>
<?php
if ($_GET[action]=="dgsp")
{
?>
<img src="image/cart/behav_01.gif" width="20" height="14"><font color="#33CCFF">订购商品</font><br>
</div>
<table width="425" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFCCFF">
<form name="frmspin" method="post" action="mycart.php?action=incart">
<tr>
<td width="71"><div align="right">
<input name="f_id" type="hidden" id="f_id" value="<?php echo $_GET[cpid]; ?>">
品名:</div></td><?php
//从数据库中读出产品信息
$sql="select * from shangpin where sp_id=$_GET[cpid]";
$rst=exesql($conf_db,$sql,$db,"未找到商品!","popup","yes","rst");
?>
<td width="205"><input name="f_name" type="text" id="f_name" readonly value="<?php echo $rst[sp_name]; ?>"></td>
<td width="141" rowspan="4" valign="middle"><div align="center"><img src="<?php
if (empty($rst[sp_img]))
echo $conf_fimgpath."defult.jpg";
else {
if ($rst[sp_imgflag]==1)
echo $conf_fimgpath.$_SESSION[wb_id]."/".$rst[sp_img];
else
echo $conf_fimgpath.$rst[sp_img];}
?>" width="120" height="120"></div></td>
</tr>
<tr>
<td><div align="right">价格:</div></td>
<td><input name="f_gold" type="text" id="f_gold" readonly value="<?php echo $rst[sp_gold]; ?>"></td>
</tr>
<tr>
<td><div align="right">介绍:</div></td>
<td><textarea name="textarea" cols="25" rows="4" wrap="VIRTUAL"><?php echo $rst[sp_text]; ?></textarea></td>
</tr>
<tr>
<td><div align="right">数量:</div></td>
<td><input name="f_num" type="text" id="f_num2" onChange="checknum(document.frmspin.f_num.value)" value="1" size="10"></td>
</tr>
<tr>
<td colspan="3"><div align="center">
<!--<input type="submit" name="Submit2" value="放入购物车">-->
<input name="imageField" type="image" src="image/cart/buy.gif" width="79" height="17" border="0">
</div></td>
</tr>
</form>
</table>
<?php } ?>
</body>
</html>
2. session操作也可以写一个类来首先。
3. 重复的session_start();4.
// if ((! is_array($splist)) || ((count($splist)-1) != $this->f_num))
return "参数传输错误,请传入以自定义字段名为下标且元数个数吻合的数组!";
虽然函数返回了错误信息,但程序仍在继续运行。5. 代码比较混乱
1. 建议使用isset代替session_is_registered
2. session操作也可以写一个类来首先。
3. 重复的session_start();4.
// if ((! is_array($splist)) || ((count($splist)-1) != $this->f_num))
return "参数传输错误,请传入以自定义字段名为下标且元数个数吻合的数组!";
虽然函数返回了错误信息,但程序仍在继续运行。5. 代码比较混乱
呵,,,一二三条建议采纳中四:程序仍在运行,是因为我给出的网页源码我已经说明了,是使用的例子,都是按正常情况来的。。所以没有写出错处理。。五:代码混乱,是因为我复制进来的时候,变形了
如果你说的代码不是指类,而是批网页的话,,在DW里看很规矩
错误处理是必须的,因为你无法预测到会有如何的状况发生//如果你说的代码不是指类,而是批网页的话,,在DW里看很规矩
为什么oo会取代procedure?
如果在html中掺杂大段的程序代码是不错的选择,那么封装只会变得没有意义