php 購物車完整實現(xiàn)代碼
來源:易賢網(wǎng) 閱讀:4778 次 日期:2014-10-08 14:36:11
溫馨提示:易賢網(wǎng)小編為您整理了“php 購物車完整實現(xiàn)代碼”,方便廣大網(wǎng)友查閱!

1、商品展示頁面

代碼如下:

<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> </td>

<td width=113><font color=ef9c3e>【<?php echo $info[mingcheng];?>】</font></td>

</tr>

<tr>

<td height=16> </td>

<td><font color=910800>【市場價:<?php echo $info[shichangjia];?>】</font></td>

</tr>

<tr>

<td height=16> </td>

<td><font color=dd4679>【會員價:<?php echo $info[huiyuanjia];?>】</font></td>

</tr>

<tr>

<td height=16> </td>

<td>【<a href=lookinfo.php?id=<?php echo $info[id];?>>查看信息</a>】</td>

</tr>

<tr>

<td height=16> </td>

<td>【<a href=addgouwuche.php?id=<?php echo $info[id];?>>放入購物車</a>】</td>

</tr>

<tr>

<td height=16> </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

代碼如下:

<?php

session_start();

include(conn.php);

if($_session[username]==)

{

echo <script>alert('請先登錄后購物!');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

代碼如下:

<?php

session_start();

if($_session[username]==)

{

echo <script>alert('請先登錄,后購物!');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> </td>

<td width=590 valign=top><table width=550 height=10 border=0 align=center cellpadding=0 cellspacing=0>

<tr>

<td> </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>市場價</div></td>

<td width=64 bgcolor=#ffffff><div align=center>會員價</div></td>

<td width=51 bgcolor=#ffffff><div align=center>折扣</div></td>

<td width=66 bgcolor=#ffffff><div align=center>小計</div></td>

<td width=71 bgcolor=#ffffff><div align=center>操作</div></td>

</tr>

<?php

/**

* 購物車 商品數(shù)量管理

* edit www.jbxue.com

*/

$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>去收銀臺</a></div></td>

<td width=125><div align=center><a href=gouwu1.php?qk=yes>清空購物車</a></div></td>

<td width=125><div align=left>總計:<?php echo $total;?></div></td>

</tr>

</table>

</div></td>

</tr>

<?php

}

?>

</table></td>

</tr>

</form>

</table></td>

</tr>

</table>

3、文件gouwu2.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> </td>

<td width=590 valign=top><table width=550 height=15 border=0 align=center cellpadding=0 cellspacing=0>

<tr>

<td> </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 www.jbxue.com

*/

function chkinput(form)

{

if(form.name.value==)

{

alert(請輸入收貨人姓名!);

form.name.select();

return(false);

}

if(form.dz.value==)

{

alert(請輸入收貨人地址!);

form.dz.select();

return(false);

}

if(form.yb.value==)

{

alert(請輸入收貨人郵編!);

form.yb.select();

return(false);

}

if(form.tel.value==)

{

alert(請輸入收貨人聯(lián)系電話!);

form.tel.select();

return(false);

}

if(form.email.value==)

{

alert(請輸入收貨人e-mail地址!);

form.email.select();

return(false);

}

if(form.email.value.indexof(@)<0)

{

alert(收貨人e-mail地址格式輸入錯誤!);

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=個人送貨>個人送貨</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>簡單留言:</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

代碼如下:

<?php

$conn=mysql_connect(localhost,root,) or die(數(shù)據(jù)庫服務(wù)器連接錯誤.mysql_error());

mysql_select_db(shop,$conn) or die(數(shù)據(jù)庫訪問錯誤.mysql_error());

mysql_query(set character set gb2312);

mysql_query(set names gb2312);

?>

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:php 購物車完整實現(xiàn)代碼
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報警專用圖標(biāo)