最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php 購物車完整實(shí)現(xiàn)代碼

 更新時(shí)間:2014年06月05日 00:58:46   作者:  
本文介紹一個(gè)php實(shí)現(xiàn)的購物車代碼,功能實(shí)現(xiàn)比較完整,實(shí)現(xiàn)了購物車、訂貨人信息、會(huì)員價(jià)等功能,還是不錯(cuò)的,有需要的朋友,可以參考下

1、商品展示頁面

復(fù)制代碼 代碼如下:

<table width="255"  border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="130" rowspan="6"><div align="center">
<?php
        if(trim($info[tupian]==""))
     {
       echo "暫無圖片";
     }
     else
     {
?>
<img src="<?php echo $info[tupian];?>" width="130" height="100" border="0">
<?php
  }
?>
</div></td>
  <td width="20" height="16">&nbsp;</td>
  <td width="113"><font color="EF9C3E">【<?php echo $info[mingcheng];?>】</font></td>
 </tr>
 <tr>
  <td height="16">&nbsp;</td>
  <td><font color="910800">【市場(chǎng)價(jià):<?php echo $info[shichangjia];?>】</font></td>
 </tr>
 <tr>
  <td height="16">&nbsp;</td>
  <td><font color="DD4679">【會(huì)員價(jià):<?php echo $info[huiyuanjia];?>】</font></td>
 </tr>
 <tr>
  <td height="16">&nbsp;</td>
  <td>【<a href="lookinfo.php?id=<?php echo $info[id];?>">查看信息</a>】</td>
 </tr>
 <tr>
  <td height="16">&nbsp;</td>
  <td>【<a href="addgouwuche.php?id=<?php echo $info[id];?>">放入購物車</a>】</td>
 </tr>
 <tr>
  <td height="16">&nbsp;</td>
  <td><font color="13589B">【剩余數(shù)量:
      <?php 
      if(($info[shuliang]-$info[cishu])>0)
      {
         echo ($info[shuliang]-$info[cishu]);
      }
      else
      {
         echo "已售完";
      }
      ?>】</font></td>
 </tr>
 </table>
     <?php
      }
     ?>    
</table>

2、文件addgouwuche.php

復(fù)制代碼 代碼如下:

<?php
session_start();
include("conn.php");

if($_SESSION[username]=="")
 {
  echo "<script>alert('請(qǐng)先登錄后購物!');history.back();</script>"; 
  exit;
 }
  $id=strval($_GET[id]);
$sql=mysql_query("select * from shangpin where id='".$id."'",$conn); 
$info=mysql_fetch_array($sql);
if($info[shuliang]<=0)
 {
   echo "<script>alert('該商品已經(jīng)售完!');history.back();</script>";
   exit;
 }
  $array=explode("@",$_SESSION[producelist]);
  for($i=0;$i<count($array)-1;$i++)
    {
  if($array[$i]==$id)
   {
      echo "<script>alert('該商品已經(jīng)在您的購物車中!');history.back();</script>";
   exit;
   }
 }
  $_SESSION[producelist]=$_SESSION[producelist].$id."@";
  $_SESSION[quatity]=$_SESSION[quatity]."1@";

  header("location:gouwu1.php");
?>

3、文件gouwu1.php

復(fù)制代碼 代碼如下:

<?php
 session_start();
 if($_SESSION[username]=="")
  {
    echo "<script>alert('請(qǐng)先登錄,后購物!');history.back();</script>";
 exit;
  }  
?>
<?php
 include("top.php");
?>
<table width="800" height="438" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="200" height="438" valign="top" bgcolor="#E8E8E8"><div align="center">
 <?php include("left.php");?>
    </div></td>
    <td width="10" background="images/line2.gif">&nbsp;</td>
    <td width="590" valign="top"><table width="550" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>    
      <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
        <form name="form1" method="post" action="gouwu1.php">
          <tr>
 <td height="25" bgcolor="#555555"><div align="center" style="color: #FFFFFF"><?php echo $_SESSION[username];?>的購物車</div></td>
          </tr>
          <tr>
 <td  bgcolor="#555555"><table width="500" border="0" align="center" cellpadding="0" cellspacing="1">
<?php
   session_start();
     session_register("total");
     if($_GET[qk]=="yes")
     {
        $_SESSION[producelist]="";
     $_SESSION[quatity]=""; 
     }
      $arraygwc=explode("@",$_SESSION[producelist]);
      $s=0;
      for($i=0;$i<count($arraygwc);$i++)
      {
          $s+=intval($arraygwc[$i]);
      }
     if($s==0 )
       {
       echo "<tr>";
   echo" <td height='25' colspan='6' bgcolor='#FFFFFF' align='center'>您的購物車為空!</td>";
   echo"</tr>";
    }
     else
      { 
   ?>
<tr>
  <td width="125" height="25" bgcolor="#FFFFFF"><div align="center">商品名稱</div></td>
  <td width="52" bgcolor="#FFFFFF"><div align="center">數(shù)量</div></td>
  <td width="64" bgcolor="#FFFFFF"><div align="center">市場(chǎng)價(jià)</div></td>
  <td width="64" bgcolor="#FFFFFF"><div align="center">會(huì)員價(jià)</div></td>
  <td width="51" bgcolor="#FFFFFF"><div align="center">折扣</div></td>
  <td width="66" bgcolor="#FFFFFF"><div align="center">小計(jì)</div></td>
  <td width="71" bgcolor="#FFFFFF"><div align="center">操作</div></td>
</tr>
<?php
/**
 * 購物車 商品數(shù)量管理
 * Edit m.fzitv.net
*/
$total=0;
$array=explode("@",$_SESSION[producelist]);
$arrayquatity=explode("@",$_SESSION[quatity]);

     while(list($name,$value)=each($_POST))
        {
       for($i=0;$i<count($array)-1;$i++)
       {
         if(($array[$i])==$name)
      {
        $arrayquatity[$i]=$value;  
      }
       }       
     }

    $_SESSION[quatity]=implode("@",$arrayquatity);

    for($i=0;$i<count($array)-1;$i++)
     { 

       $id=$array[$i];
       $num=$arrayquatity[$i];

      if($id!="")
       {
       $sql=mysql_query("select * from shangpin where id='".$id."'",$conn);
       $info=mysql_fetch_array($sql);
       $total1=$num*$info[huiyuanjia];
       $total+=$total1;
       $_SESSION["total"]=$total;
   ?>
<tr>
  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[mingcheng];?></div></td>
  <td height="25" bgcolor="#FFFFFF"><div align="center">
      <input type="text" name="<?php echo $info[id];?>" size="2" class="inputcss" value=<?php echo $num;?>>
  </div></td>
  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[shichangjia];?>元</div></td>
  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[huiyuanjia];?>元</div></td>
  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo @(ceil(($info[huiyuanjia]/$info[shichangjia])*100))."%";?></div></td>
  <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info[huiyuanjia]*$num."元";?></div></td>
  <td height="25" bgcolor="#FFFFFF"><div align="center"><a href="removegwc.php?id=<?php echo $info[id]?>">移除</a></div></td>
</tr>
<?php         
         }
     }
?>
<tr>
  <td height="25" colspan="8" bgcolor="#FFFFFF"><div align="right">
      <table width="500" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="125"><div align="center">
 <input type="submit" value="更改商品數(shù)量" class="buttoncss">
          </div></td>
          <td width="125"><div align="center"><a href="gouwu2.php">去收銀臺(tái)</a></div></td>
          <td width="125"><div align="center"><a href="gouwu1.php?qk=yes">清空購物車</a></div></td>
          <td width="125"><div align="left">總計(jì):<?php echo $total;?></div></td>
        </tr>
      </table>
  </div></td>
 </tr>
 <?php
    }
   ?>
</table></td>
</tr>
</form>
    </table></td>
  </tr>
</table>

3、文件gouwu2.php

復(fù)制代碼 代碼如下:

<table width="800" height="438" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="200" height="438" valign="top" bgcolor="#E8E8E8"><div align="center">
 <?php include("left.php");?>
    </div></td>
    <td width="10" background="images/line2.gif">&nbsp;</td>
    <td width="590" valign="top"><table width="550" height="15" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
      <table width="550" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="25" bgcolor="#555555"><div align="center" style="color: #FFFFFF">收貨人信息</div></td>
        </tr>
        <tr>
          <td height="300" bgcolor="#555555"><table width="550" height="300" border="0" align="center" cellpadding="0" cellspacing="1">
<script language="javascript">
/**
 * 購物車 收貨人信息
 * Edit m.fzitv.net
*/
function chkinput(form)
    {
      if(form.name.value=="")
       {
      alert("請(qǐng)輸入收貨人姓名!");
      form.name.select();
      return(false);

    }
    if(form.dz.value=="")
       {
      alert("請(qǐng)輸入收貨人地址!");
      form.dz.select();
      return(false);

    }
    if(form.yb.value=="")
       {
      alert("請(qǐng)輸入收貨人郵編!");
      form.yb.select();
      return(false);

    }
    if(form.tel.value=="")
       {
      alert("請(qǐng)輸入收貨人聯(lián)系電話!");
      form.tel.select();
      return(false);

    }
    if(form.email.value=="")
       {
      alert("請(qǐng)輸入收貨人E-mail地址!");
      form.email.select();
      return(false);

    }
    if(form.email.value.indexOf("@")<0)
     {
        alert("收貨人E-mail地址格式輸入錯(cuò)誤!");
        form.email.select();
        return(false);

     }
    return(true);    
    }     
     </script>
     <form name="form1" method="post" action="savedd.php" onSubmit="return chkinput(this)">
      <tr>
 <td width="100" height="25" bgcolor="#FFFFFF"><div align="center">收貨人姓名:</div></td>
 <td width="183" bgcolor="#FFFFFF"><div align="left"><input type="text" name="name" size="25" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></div></td>
 <td width="86" bgcolor="#FFFFFF"><div align="center">性別:</div></td>
 <td width="176" bgcolor="#FFFFFF"><div align="left">
 <select name="***">
  <option selected value="男">男</option>
  <option value="女">女</option>
 </select>
 </div></td>
 </tr>
 <tr>
 <td height="25" bgcolor="#FFFFFF"><div align="center">詳細(xì)地址:</div></td>
 <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"><input name="dz" type="text" class="inputcss" id="dz" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="25">
 </div></td>
 </tr>
 <tr>
 <td height="25" bgcolor="#FFFFFF"><div align="center">郵政編碼:</div></td>
 <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"><input type="text" name="yb" size="25" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></div></td>
 </tr>
 <tr>
 <td height="25" bgcolor="#FFFFFF"><div align="center">聯(lián)系電話:</div></td>
 <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"><input type="text" name="tel" size="25" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></div></td>
 </tr>
 <tr>
 <td height="25" bgcolor="#FFFFFF"><div align="center">電子郵箱:</div></td>
 <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left"><input type="text" name="email" size="25" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></div></td>
 </tr>
 <tr>
 <td height="25" bgcolor="#FFFFFF"><div align="center">送貨方式:</div></td>
 <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left">
 <select name="shff" id="shff">
  <option selected value="普通平郵">普通平郵</option>
  <option value="特快專遞">特快專遞</option>
  <option value="送貨上門">送貨上門</option>
  <option value="個(gè)人送貨">個(gè)人送貨</option>
  <option value="E-mail">E-mail</option>
      </select>
</div></td>
 </tr>
 <tr>
 <td height="25" bgcolor="#FFFFFF"><div align="center">支付方式:</div></td>
 <td height="25" colspan="3" bgcolor="#FFFFFF"><div align="left">
 <select name="zfff" id="zfff">
  <option selected value="建設(shè)銀行匯款">建設(shè)銀行匯款</option>
  <option value="交通銀行匯款">交通銀行匯款</option>
  <option value="郵局匯款">郵局匯款</option>
  <option value="網(wǎng)上支付">網(wǎng)上支付</option>
 </select>
 </div></td>
 </tr>
 <tr>
 <td height="100" bgcolor="#FFFFFF"><div align="center">簡(jiǎn)單留言:</div></td>
 <td height="100" colspan="3" bgcolor="#FFFFFF"><div align="left">
 <textarea name="ly" cols="60" rows="8" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></textarea>
</div></td>
 </tr>
 <tr>
 <td height="25" colspan="4" bgcolor="#FFFFFF"><div align="center"><input type="submit" value="提交訂單" class="buttoncss">
 </div></td>
 </tr>
   </form>
          </table></td>
        </tr>
      </table></td>
  </tr>
</table>
<?php
 if($_GET[dingdanhao]!="")
  {  $dd=$_GET[dingdanhao];
     session_start();

     $array=explode("@",$_SESSION[producelist]);
  $sum=count($array)*20+260;
    echo" <script language='javascript'>";
 echo" window.open('showdd.php?dd='+'".$dd."','newframe','top=150,left=200,width=600,height=".$sum.",menubar=no,toolbar=no,location=no,scrollbars=no,status=no ')";
 echo "</script>";

  }
?>

4、數(shù)據(jù)庫配置文件conn.php
 

復(fù)制代碼 代碼如下:

<?php
$conn=mysql_connect("localhost","root","") or die("數(shù)據(jù)庫服務(wù)器連接錯(cuò)誤".mysql_error());
mysql_select_db("shop",$conn) or die("數(shù)據(jù)庫訪問錯(cuò)誤".mysql_error());
mysql_query("set character set gb2312");
mysql_query("set names gb2312");
?>

相關(guān)文章

  • Yii2框架實(shí)現(xiàn)數(shù)據(jù)庫常用操作總結(jié)

    Yii2框架實(shí)現(xiàn)數(shù)據(jù)庫常用操作總結(jié)

    本篇文章主要介紹了Yii2框架實(shí)現(xiàn)數(shù)據(jù)庫常用操作總結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • 利用PHP獲取漢字首字母并且分組排序詳解

    利用PHP獲取漢字首字母并且分組排序詳解

    這篇文章主要給大家介紹了關(guān)于如何利用PHP獲取漢字首字母并且分組排序的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用php具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-10-10
  • Aliyun Linux 編譯安裝 php7.3 tengine2.3.2 mysql8.0 redis5的過程詳解

    Aliyun Linux 編譯安裝 php7.3 tengine2.3.2 mysql8.0 redis5的過程詳解

    這篇文章主要介紹了Aliyun Linux 編譯安裝 php7.3 tengine2.3.2 mysql8.0 redis5,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-10-10
  • 使用PHP靜態(tài)變量當(dāng)緩存的方法

    使用PHP靜態(tài)變量當(dāng)緩存的方法

    本文介紹如何使用PHP靜態(tài)變量當(dāng)緩存,減少代碼重復(fù)執(zhí)行,優(yōu)化程序性能
    2013-11-11
  • php檢測(cè)useragent版本示例

    php檢測(cè)useragent版本示例

    這篇文章主要介紹了php檢測(cè)useragent版本的示例,需要的朋友可以參考下
    2014-03-03
  • Laravel學(xué)習(xí)教程之IOC容器的介紹與用例

    Laravel學(xué)習(xí)教程之IOC容器的介紹與用例

    最近在學(xué)習(xí)laravel,正好學(xué)習(xí)到了ioc容器,但發(fā)現(xiàn)網(wǎng)上這方面的資料較少,所以將自己學(xué)習(xí)的總結(jié)下,下面這篇文章主要給大家介紹了關(guān)于Laravel學(xué)習(xí)教程之IOC容器的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08
  • Swoole?webSocket消息服務(wù)系統(tǒng)壓力測(cè)試解析

    Swoole?webSocket消息服務(wù)系統(tǒng)壓力測(cè)試解析

    這篇文章主要為大家介紹了Swoole?webSocket消息服務(wù)系統(tǒng)壓力測(cè)試解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • PHP如何解決微信文章圖片防盜鏈

    PHP如何解決微信文章圖片防盜鏈

    這篇文章主要介紹了PHP如何解決微信文章圖片防盜鏈,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-12-12
  • 如何使用OPCache提升PHP的性能

    如何使用OPCache提升PHP的性能

    這篇文章主要介紹了如何使用OPCache提升PHP的性能,幫助大家更好的理解和學(xué)習(xí)使用PHP,感興趣的朋友可以了解下
    2021-04-04
  • thinkPHP控制器變量在模板中的顯示方法示例

    thinkPHP控制器變量在模板中的顯示方法示例

    這篇文章主要介紹了thinkPHP控制器變量在模板中的顯示方法,結(jié)合實(shí)例形式簡(jiǎn)單分析了thinkPHP控制器變量在模板中的三種常見的顯示操作實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2018-03-03

最新評(píng)論

德庆县| 通辽市| 津南区| 新兴县| 安国市| 钦州市| 延寿县| 田阳县| 伊川县| 鞍山市| 建宁县| 垦利县| 建始县| 武定县| 贵定县| 大理市| 德庆县| 登封市| 天门市| 阳城县| 布尔津县| 清新县| 开江县| 漯河市| 哈巴河县| 余庆县| 宜昌市| 嘉兴市| 屏南县| 桓仁| 泸西县| 宁海县| 宜宾县| 兴安盟| 长寿区| 理塘县| 保定市| 辰溪县| 炉霍县| 甘泉县| 日土县|