Presentation is loading. Please wait.

Presentation is loading. Please wait.

購 物 車購 物 車 1. 先 Create 購物車的 table 購物車的主表 shopping shopping( shoppingid char(40), not null, PK shoppingtime datetime ID char(10) ) 購物車的副表 shopping_detail.

Similar presentations


Presentation on theme: "購 物 車購 物 車 1. 先 Create 購物車的 table 購物車的主表 shopping shopping( shoppingid char(40), not null, PK shoppingtime datetime ID char(10) ) 購物車的副表 shopping_detail."— Presentation transcript:

1 購 物 車購 物 車 1. 先 Create 購物車的 table 購物車的主表 shopping shopping( shoppingid char(40), not null, PK shoppingtime datetime ID char(10) ) 購物車的副表 shopping_detail shopping_detail ( sid int, autoincrement shoppingid char(40) not null, Pid char(20), amount int, )

2 修改檔案 Myhome.php  加入登出, 後台管理, 查看購物車選項 0315.Php  登入成功後回到 myhome.php 加入登入者 SESSION[ “ loginid ” ] Logout.php  清空登入者 SESSION[ “ loginid ” ] Item.htm  多 [ 檢視購物 ](view.php) 選項

3 身分證: 密碼: 查看購物車 登出 後台管理 查看購物車 修改 myhome.php

4 <? // 連線到資料庫 include("conn.php"); if (empty($_SESSION['buycarid'])){ // 產生購物單編號 mt_srand((double)microtime()*1000000); $shpid=crypt(uniqid(mt_rand())); $_SESSION['buycarid']=$shpid; } if(empty($_SESSION["shoppinglist"])){ $_SESSION["shoppinglist"]=""; } $_SESSION["shoppinglist"]=$_SESSION["shoppinglist"].$_GET["buyid"].";"; // 顯示結果 echo " 您將訂購編號: ".$_GET["buyid"]." 的產品。 "; echo " 目前訂購: "; ?> 產品編號 產品名稱 <? $buyitem = strtok($_SESSION["shoppinglist"],";"); while($buyitem) { $str="select * from product where Pid='".$buyitem."'"; $result=mysql_query($str); if($row=mysql_fetch_array($result)){ ?> <? } $buyitem = strtok(";"); } ?> <? echo "[ 繼續訂購 [ 結帳 ]";?> 利用 session 產生購物編號 購物車 putin.php

5 <? // 連線到資料庫 include("conn.php"); if (empty($_SESSION["shoppinglist"])){ echo " 購物車是空的 "; header("Refresh:2;url=myhome.php"); exit; } ?> 產品編號 產品名稱 <? $buyitem = strtok($_SESSION["shoppinglist"],";"); while($buyitem) { $str="select * from product where Pid='".$buyitem."'"; $result=mysql_query($str); if($row=mysql_fetch_array($result)){ ?> <? } $buyitem = strtok(";"); } ?> <? echo "[ 繼續訂購 [ 結帳 ] [ 清空購物車 ]"; ?> 檢視購物車 viewcar.php

6 購物車 clearcar.php 清空購物車 <? $_SESSION["shoppinglist"]=""; echo " 已清空 "; echo "[ 繼續訂購 ]"; ?>

7 <? if($_SESSION['ok']==0){ // 未登入 echo " 需要先登入才能結帳 "; header("Refresh:5;url=myhome.php"); exit; } // 連線到資料庫 include("conn.php"); if (empty($_SESSION['buycarid'])){ echo " 沒有購買任何東西 "; }else{ // 寫入 shopping $str="insert into shopping (shoppingid,shoppingtime,ID) values ('".$_SESSION['buycarid']."',now(),'".$_SESSION['loginid']."')"; mysql_query($str); } $buyitem = strtok($_SESSION["shoppinglist"],";"); while($buyitem) { $str="insert into shopping_detail (shoppingid,Pid) values ('".$_SESSION['buycarid']."','".$buyitem."')"; mysql_query($str); $buyitem = strtok(";"); } $_SESSION["shoppinglist"]=""; $_SESSION['buycarid']=""; echo " 結帳完畢 [ 繼續訂購 ";?> 結帳 pay.php

8 <? include("iflogin.php"); include("conn.php"); include("item.htm"); // 串連 table $str="select shopping.shoppingid as shoppingid,shopping.shoppingtime as shoppingtime,member.Name as Name from shopping,member where shopping.ID=member.ID and member.ID='".$_SESSION['loginid']."' order by shopping.shoppingtime desc"; $result=mysql_query($str); ?> 以下是已訂購的單據: 編號 購買編號 購買時間 購買人 <? $serial=1; while ($row=mysql_fetch_array($result)){ ?> target=_blank> <? $serial=$serial+1; } ?> <? include("ctu.htm"); ?> 檢視結果 view.php

9 <? include("iflogin.php"); include("conn.php"); // 串連 table $str="select shopping_detail.Pid as Pid,shopping_detail.amount as amount,product.Pname as Pname,product.price as price from shopping_detail,product where shopping_detail.shoppingid='".$_GET["buyid"]."' and shopping_detail.Pid=product.Pid"; $result=mysql_query($str); ?> 以下是訂購的產品: 編號 產品編號 產品名稱 單價 數量 <? $serial=1; $total=0; while ($row=mysql_fetch_array($result)){ ?> <? $total=$total+$row["price"]*$row["amount"]; $serial=$serial+1; } ?> 總金額 購物細表 viewdetail.php

10 if(empty($_SESSION["shoppinglist"])){ $_SESSION["shoppinglist"]=""; } if($_GET["del"]==1){ // 刪除 // 由 $_SESSION["shoppinglist"] 找出要刪除的資料 $_SESSION["shoppinglist"]=ereg_replace($_GET["delid"].";","",$_SESSION["shoppinglist"]); }else{ $_SESSION["shoppinglist"]=$_SESSION["shoppinglist"].$_GET["buyid"].";"; // 顯示結果 echo " 您將訂購編號: ".$_GET["buyid"]." 的產品。 "; echo " 目前訂購: "; } ?> 產品編號 產品名稱 刪除 <? $buyitem = strtok($_SESSION["shoppinglist"],";"); while($buyitem) { $str="select * from product where Pid='".$buyitem."'"; $result=mysql_query($str); if($row=mysql_fetch_array($result)){ ?> > 刪除 修改 putin.php 變成可以刪除

11 if (empty($_SESSION['buycarid']) or empty($_SESSION['shoppinglist'])){ echo " 沒有購買任何東西 "; echo " 結帳完畢 [ 繼續訂購 ]"; exit; }else{ // 寫入 shopping $str="insert into shopping (shoppingid,shoppingtime,ID) values ('".$_SESSION['buycarid']."',now(),'".$_SESSION['loginid']."')"; mysql_query($str); } $buyitem = strtok($_SESSION["shoppinglist"],";"); while($buyitem) { $str="insert into shopping_detail (shoppingid,Pid) values ('".$_SESSION['buycarid']."','".$buyitem."')"; mysql_query($str); $buyitem = strtok(";"); } 修改 pay.php

12 $buyitem = strtok($_SESSION["shoppinglist"],";"); $content=" 您好 \n 您於建國購物網購買了下列產品: \n"; while($buyitem) { $str1="select Pname from product where Pid='".$buyitem."'"; $result=mysql_query($str1); $row=mysql_fetch_array($result); $content=$content.$buyitem." ".$row["Pname"]."\n"; $str="insert into shopping_detail (shoppingid,Pid) values ('".$_SESSION['buycarid']."','".$buyitem."')"; mysql_query($str); $buyitem = strtok(";"); } $_SESSION["shoppinglist"]=""; $_SESSION['buycarid']=""; // 寄出 mail 給購買人 $poster=" 建國購物網 "; $email="abc@aa.bb.cc"; $extra="from: \"". $poster. "\" \nContent-Type: text/plain;charset=\"big5\"\n Content-Transfer-Encoding: 7bit\n"; mail("rcjao@ctu.edu.tw"," 購物 ",$content,$extra); 修改 pay.php 結合 mail 功能


Download ppt "購 物 車購 物 車 1. 先 Create 購物車的 table 購物車的主表 shopping shopping( shoppingid char(40), not null, PK shoppingtime datetime ID char(10) ) 購物車的副表 shopping_detail."

Similar presentations


Ads by Google