導航:首頁 > 編程語言 > php購物車程序

php購物車程序

發布時間:2023-07-25 23:24:02

⑴ 【高分】急求用php寫的購物車代碼!!!!!(十萬火急)如果您提供的好用還有加分!!!

我也要弄一個這種購物車,
我去寫個,貼出來,【嘿嘿,今天上午新寫的】。
我懶得新建資料庫,用的是我的資料庫。
你按照我的改一下就能用了
本人水平有限,高手請指正。
你,大,爺的,雖然不咋地,保證能用
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
經過調試,
//$my->add_cart(45,3,"茶幾系列");//新增購物
//$my->updata_cart(13,13,8); //更新購物
//$my->del_cart(12,5,'Guest'); //刪除一種購物
//$my->empty_cart('Guest'); //清空購物車
$ok=$my->get_cart('Guest'); //返回購物車
這些都可用
-------------------------------------------------------------------
<?php

class Cart
{

public $totalCost=0; //商品總金額

function cart($host,$usr,$pwd,$db)
{
mysql_connect($host,$usr,$pwd) or die(mysql_error);
mysql_select_db($db) or die(mysql_error);
mysql_query("SET Names GBk");
//只要有人訪問,就自動清除一天前所有沒付款的訂單;
$sql="delete FROM shopcart WHERE TO_DAYS( NOW( )) - TO_DAYS( ptime ) >=1 and payment=0";
mysql_query($sql);

}

// 彈出提示
function alter($Str,$Url)
{
echo "<Script language='javaScript'> alert('".$Str."');</Script>";
echo "<meta http-equiv=refresh content=0;URL=".$Url.">";
}

//增加購物;三個參數:pid:產品ID,ptl:產品數量,pcid:產品類別
//查詢資料庫,是否存在此人在本日內訂過本產品
//如果訂過,那麼數量累加,否則插入一個資料庫行
function add_cart($pid,$ptl=1,$pcid)
{
if($ptl>=100 || $ptl<=0)
{
$this->alter("最多買99件,最少1件","index.php");
die();
}

if(!$_SESSION['usr']) { $usr='Guest';}
else { $usr=$_SESSION['usr'];}

$sql="select * from shopcart where pid='".$pid."' and usr='".$usr."' and pcid='".$pcid."'";
$ex=mysql_query($sql);
$ex1=mysql_fetch_array($ex);

if(!$ex1)
{
$sql="select * from proct where ID='".$pid."' and class1='".$pcid."'";
$ok=mysql_query($sql);
$rs=mysql_fetch_array($ok);

if($rs)
{
$totalCost= $rs['Price'] * $ptl;

$sql="insert into shopcart(usr,pid,pname,ptl,price,pcid,psum,payment) Values(";
$sql.="'".$usr."',";
$sql.="'".$rs['ID']."',";
$sql.="'".$rs['Name']."',";
$sql.="'".$ptl."',";
$sql.="'".$rs['Price']."',";
$sql.="'".$rs['Class1']."',";
$sql.="'".$totalCost."',";
$sql.="'0')";

mysql_query($sql) or die(mysql_error());
if($ok) { $this->alter("購物成功","index.php"); }
else { $this->alter("購物失敗","index.php"); }

}
else
{
$this->alter("不存在的商品,或者參數錯誤","index.php");
die();
}
}
else
{
$sql="update shopcart set ptl= ptl+1,psum = psum+price where ID='".$ex1['ID']."'";
mysql_query($sql);
$this->alter("更新數量成功","index.php");
}

}

//更新購物車的單個產品的數量;
function updata_cart($cid,$ptl,$pid)
{
if($ptl>=100||$ptl<=0)
{
$this->alter('產品數量不對!','index.php');
die();
}
$sql="select * from shopcart where ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!ok) { alter("參數發生錯誤","index.php");}
else
{
$sql="update shopcart set ptl='".$ptl."',psum=price * '".$ptl."' where ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!ok) { $this->alter("更新失敗","index.php");}
else { $this->alter("更新成功","index.php");}
}
}
function del_cart($cid,$pid,$usr)
{
$sql="delete from shopcart where usr='".$usr."' and ID='".$cid."' and pid='".$pid."'";
$ok=mysql_query($sql);
if(!$ok) {$this->alter("刪除失敗","index.php");}
else {$this->alter("刪除成功","index.php");}
}

function empty_cart($usr)
{
$sql="delete from shopcart where usr='".$usr."'";
mysql_query($sql) or die(mysql_error);
}

function get_cart($usr)
{
$sql="select * from shopcart where usr='".$usr."'";
$ok=mysql_query($sql);
return $ok;
}

}
$my = new Cart("localhost","root","root","mybbs");
//$my->add_cart(45,3,"茶幾系列");
//$my->updata_cart(13,13,8);
//$my->del_cart(12,5,'Guest');
//$my->empty_cart('Guest');
$ok=$my->get_cart('Admin');

echo "usr pid pname ptl price pcid psum payment ptime <br><hr><br>";
while($rs=mysql_fetch_array($ok))
{
echo $rs[1]."->".$rs[2]."->".$rs[3]."->".$rs[4]."->".$rs[5]."->".$rs[6]."->".$rs[7]."->".$rs[8]."->".$rs[9]."<br>";

}

?>

、、、、、、、、、、、、、、、、、SQL、、、、、、、、、、、、、、

CREATE TABLE IF NOT EXISTS `shopcart` (
`ID` int(10) NOT NULL auto_increment,
`usr` varchar(50) NOT NULL,
`pid` int(5) NOT NULL,
`pname` varchar(100) NOT NULL,
`ptl` int(3) NOT NULL,
`price` decimal(50,2) NOT NULL default '0.00',
`pcid` varchar(100) NOT NULL,
`psum` decimal(50,2) NOT NULL default '0.00',
`payment` tinyint(1) NOT NULL,
`ptime` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`)
)

proct 裡面用的ID CLASS1是

`ID` int(6) NOT NULL auto_increment,
`Class1` varchar(20) NOT NULL,
`Price` int(6) NOT NULL,

⑵ 購物車滿100減2元,200減5元 300減7元,php這個代碼怎麼寫,腦殼都想破了。

$count_price = 多少錢;//購物車總金額
if($count_price >=100 && $count_price<200)
{
$count_price = $count_price-2;
}else if($count_price>=200 && $count_price<300){
$count_price = $count_price -5;
}else if($count_price>=300){
$count_price = $count_price - 7;
}

⑶ 如何用html css javascript php製作購物車

一兩句說不清楚………

用html css做出商品樣子和購物車樣子,

然後用javascript來對買這個動作做處理,把商品的信息存起來,通過js把商品信息傳遞給購物車,讓購物車能夠顯示;
另一方面把信息交給php,寫入資料庫。

我這么說你明白了么……

⑷ 跪求一份PHP購物車的源碼 只要求不到 我就一直等 等到天荒等到地老

源碼我這里沒有。而且找出來的源碼也未必適合你。
給你說一下購物車的思路吧,希望對你有幫助
1.現在互聯網的購物車.一般都採用cookie來做的.
a.用戶點擊"加入購物車",把當前物品id,按照某種形式,寫入cookie.
b.代碼思路.$_COOKIE['car']可以理解為就是購物車.裡面是物品id;
$car = $_COOKIE['car']; //先讀取購物車
$car = $car ? explode(',',$car) : array(); //如果購物車有物品,則把物品轉化成數組,如果沒有則默認成空數組;
$car[] = $goods_id; //往購物車中增加該物品;
$car = implode(','.$car); //把購物車中的所有物品id,轉化成字元串。這便於存貯在cookie中,直接存數組也可以。但是如果你需要把整個購物車信息加密的話,那就應該只有字元串了。
setcookie('car',$car,time()+3600); //購物車存1個小時,這個時間可以設置的長一點;

2.也可以通過資料庫來實現;但前提是必須要用戶登陸才可以。
table_car
uid
goods_id
datetime
1.每次用戶點擊「加入購物車」,往資料庫中寫入,該條信息就好了。
這種情況需要注意,在一定的時間段外,需要清空之前的信息。所以這里設置了datetime;

這個只是簡單的購物車原理。裡面還有一些其他細節。
1.比如說物品的數量。
2.cookie信息的加密和解密.
..........
3.才用資料庫方式,需要清空哪些購物數據

⑸ thinkphp做的session購物車,求詳細代碼。有完整例子的可以發下。非常感謝

到thinkphp官網上找一個不就可以了,上面有很多的實例啊

閱讀全文

與php購物車程序相關的資料

熱點內容
macbookpro如何修改文件內容 瀏覽:965
java穩定排序 瀏覽:53
oppo文件管理的圖片 瀏覽:335
plc編程步數怎麼計算 瀏覽:142
ipad看電腦文件 瀏覽:935
成都製作pdf文件 瀏覽:735
怎麼樣點開電腦裡面的網路連接 瀏覽:755
微信怎麼退出賬號 瀏覽:32
w微信開發者工具 瀏覽:325
資料庫還原附加 瀏覽:713
打包成exe執行文件 瀏覽:652
信豐營銷app有哪些 瀏覽:463
蘋果文件下載項如何下載 瀏覽:179
ps摳婚紗教程 瀏覽:203
如何在移動硬碟上隱藏文件夾 瀏覽:451
瑞虎8老車機怎麼刷app 瀏覽:992
學ui設計要學java嗎 瀏覽:275
淘寶票房數據源怎麼調整 瀏覽:470
iphone5s升級ios卡黑屏 瀏覽:622
u盤沒用的文件刪不了怎麼辦 瀏覽:561

友情鏈接