Home >Backend Development >PHP Tutorial > php购物车解决办法

php购物车解决办法

WBOY
WBOYOriginal
2016-06-13 13:15:03771browse

php购物车




无标题文档



首页   购物篮   历史记录   退出
  
  $con = mysql_connect("localhost", "root", "");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_selected = mysql_select_db("user",$con);
$sql="select * from produce";//查询所有商品 
$rs=mysql_query($sql,$con);//执行sql语句,得到一个结果集 
while($row=mysql_fetch_array($rs))//遍历结果集 

?> 


 


 
   
   
   
   
   
   
   
   
   
 
 php购物车解决办法 src="images/" width="123" style="max-width:90%" border="0" />货物名称:
货物价格:
&pname=echo $row["pname"] ?>">购买
 

?> 



------解决方案--------------------
你想提问的是什么? 有个 编码 方式的 文本。

你把内容用相应的源码高亮显示不是更方便别人为你解决问题吗?
------解决方案--------------------
$act=$_GET[act];
$product_id=$_GET[prcid];

if($act=="add")

$cars_id=explode(",",$_COOKIE[buypro]);
//echo "
";<br>  	//print_r($cars_id);<br>	//echo"
";
//exit;
foreach($cars_id as $pr_id)
{
if($pr_id==$product_id)
{
echo "<script>alert('您已经购买了此商品,请查看购物车!');location.href='car.php';</script>";
exit;
}
}

if(empty($_COOKIE[buypro]))
{
setcookie("buypro",$product_id,time()+3600);
setcookie("buycount","1",time()+3600);
}
else
{
$newpro=$_COOKIE[buypro].",".$product_id;
$newcount=$_COOKIE[buycount].","."1";
setcookie("buypro",$newpro,time()+3600);
setcookie("buycount",$newcount,time()+3600);
}
}
//删除
if($act=="del")
{
$buy=$_COOKIE[buypro];
$cars_id=explode(",",$buy);
$buycountary=explode(",",$_COOKIE[buycount]);
$newid=array();
$carcount=array();
for($i=0;$i {
if($cars_id[$i]!=$product_id)
{
$newid[]=$cars_id[$i];
$carcount[]=$buycountary[$i];
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn