導航:首頁 > 編程語言 > php訂單代碼

php訂單代碼

發布時間:2024-05-02 16:47:22

1. php商城 如何下訂單講解

汗 ,這怎麼能說的清楚
你只要搞清楚幾個表就可以了 當然了 我只參照過ECSHOP的 其他的沒了解過 給你說說看

首先用戶一打開網頁,然後看中的商品放進購物車 ,這個不多說了,然後用戶會直接點購買,這里判斷下用戶是否登錄,也看你是否需要用戶登錄才能購買,然後填寫資料,當然填寫過的就沒必要了,接下來就是訂單確認了。這也是你要了解的。 用戶一點確認 ,為了安全首先判斷各種必要的資料是否填寫,是否填寫正確,然後寫入兩個表 ,一個存放訂單,一個存放用戶購買的哪個商品,購買了幾件,單價多少,總價多少等等,,訂單的話看你自己想弄成什麼樣子的了,比如生成訂單看時間 $dingdan="ecshop".date('YmdHis').rand(1000,10000);這不就搞定了,很簡單的 ,當然了 我說的肯定很粗糙,不過大體思路已經出來了,在具體也不是這里能說得清楚的了

2. PHP 高手 請進來看下這段購物車代碼

$sql="SELECT name,price FROM proct WHERE id='$id'";
$id是變數,php中雖然雙引號和單引號都能表示字元串,但是不同的是,單引號不能解析變數,也就是說'$aaaa'表示的就是字元串$aaaa,而不會解析字元串!
改為:
$sql="SELECT name,price FROM proct WHERE id=$id";

3. php接收POST數據並循環輸出的代碼

在php中,表單POST提交的數據是存放在$_POST變數中.$_POST變數是一個數組,它是一個以表單欄位名作索引的數組.比如有以下表單:

<formmethod="post">
<p>姓名:<inputtype="text"name="name"value=""></p>
<p>年齡:<inputtype="text"name="age"value=""></p>
<p><inputtype="submit"value="提交"></p>
</form>

輸入值後提交,按你的要求,在php層處理輸出提交的內容,那麼可以這樣:

<?php
echo'你的姓名是:'.$_POST['name'];//其中$_POST['name']中存放的是上面表單名為name的值
echo'你今年'.$_POST['age'].'歲';//其中$_POST['age']中存放的是上面表單名為age的值
?>

如果欄位內容很多,有時就可能需要循環處理.

foreach($_POSTas$val){
echo$val;
}
或直接:
print_r($_POST);

當然處理或輸出的格式很多,以上只是一個示例.

4. thinkphp訂單號怎麼生成

function build_order_no() {

return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);

}

function guid() {

if (function_exists('com_create_guid')) {

return com_create_guid();

} else {

mt_srand((double)microtime()*10000);

$charid = strtoupper(md5(uniqid(rand(), true)));

$hyphen = chr(45);

$uuid = chr(123)

.substr($charid, 0, 8).$hyphen

.substr($charid, 8, 4).$hyphen

.substr($charid,12, 4).$hyphen

.substr($charid,16, 4).$hyphen

.substr($charid,20,12)

.chr(125);

return $uuid;

}

}

5. 【高分】急求用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,

閱讀全文

與php訂單代碼相關的資料

熱點內容
cnc玻璃精雕機編程 瀏覽:311
電腦復制中途改文件夾名字 瀏覽:496
批處理轉exe反編譯工具 瀏覽:74
pdf怎麼換成圖片 瀏覽:323
換位加密能夠按照一定 瀏覽:388
安卓開發入門pdf 瀏覽:190
日醫pdf 瀏覽:861
指定文件夾換壁紙 瀏覽:898
天玥伺服器是什麼架構 瀏覽:236
蘋果為什麼回購安卓手機 瀏覽:87
27歲程序員發型 瀏覽:196
圖庫文件夾是什麼意思 瀏覽:532
空調壓縮機隔音 瀏覽:351
簿荷閱讀app為什麼登陸不了 瀏覽:516
zigbee與單片機通信 瀏覽:439
下載伺服器錯誤怎麼辦 瀏覽:652
pdf讀取庫 瀏覽:483
如何找到底層演算法 瀏覽:329
小宅z3下載什麼app 瀏覽:816
快速列印pdf 瀏覽:636