Home > Backend Development > PHP Tutorial > 关于购物车实现的小问题 谢谢大家

关于购物车实现的小问题 谢谢大家

WBOY
Release: 2016-06-20 12:35:40
Original
970 people have browsed it

session_start();
include("conn/conn.php");
if($_SESSION[username]==""){
  echo "<script>alert('请先登录后购物!');history.back();</script>"; 
  exit;
 }
$id=strval($_GET[id]);
$sql=mysql_query("select * from tb_shangpin where id='".$id."'",$conn); 
$info=mysql_fetch_array($sql);
if($info[shuliang]   echo "<script>alert('该商品已经售完!');history.back();</script>";
   exit;
 }
  $array=explode("@",$_SESSION[producelist]);
  for($i=0;$i  if($array[$i]==$id){
     echo "<script>alert('该商品已经在您的购物车中!');history.back();</script>";
 exit;
  }
}
  $_SESSION[producelist]=$_SESSION[producelist].$id."@";
  $_SESSION[quatity]=$_SESSION[quatity]."1@";
  header("location:gouwu1.php");
?> 
上面的count ($array)为什么还要减一啊谢谢大家


回复讨论(解决方案)

因为每次增加商品时:$_SESSION[producelist]=$_SESSION[producelist].$id."@";
$_SESSION[producelist] 的内容以 @ 结束
explode 后,$array 最后一个元素为空

因为每次增加商品时:$_SESSION[producelist]=$_SESSION[producelist].$id."@";
$_SESSION[producelist] 的内容以 @ 结束
explode 后,$array 最后一个元素为空

真心谢谢你
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template