php网上购物查询代码(php小型购物网站源码)
admin 发布:2022-12-19 15:37 143
本篇文章给大家谈谈php网上购物查询代码,以及php小型购物网站源码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、要一个简单的PHP购物网站源码
- 2、【高分】急求用php写的购物车代码!!!!!(十万火急)如果您提供的好用还有加分!!!
- 3、PHP 高手 请进来看下这段购物车代码
- 4、请教关于PHP购物车代码的数据库表和字段
要一个简单的PHP购物网站源码
购物商城类的开源代码,可以用ECShop免费开源网店系统或者ThinkPHP shop开源商城系统来做,当然网上也有很多主题模板可以用。
ECShop比较适合来做简单网店系统,个人或者企业做销售产品用;
而TP shop可用于开发运营商、供货商、采购商、用户分销等多面向、多功能的商城系统,不过开发难度会稍高些,运作成本也会增高。
【高分】急求用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 product 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 brhrbr";
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`)
)
product 里面用的ID CLASS1是
`ID` int(6) NOT NULL auto_increment,
`Class1` varchar(20) NOT NULL,
`Price` int(6) NOT NULL,
PHP 高手 请进来看下这段购物车代码
$sql="SELECT name,price FROM product WHERE id='$id'";
$id是变量,php中虽然双引号和单引号都能表示字符串,但是不同的是,单引号不能解析变量,也就是说'$aaaa'表示的就是字符串$aaaa,而不会解析字符串!
改为:
$sql="SELECT name,price FROM product WHERE id=$id";
请教关于PHP购物车代码的数据库表和字段
PHP Code
div id="products-wrapper"
h1Products/h1
div class="products"
?php
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$results = $mysqli-query("SELECT * FROM cart ORDER BY id ASC");
if ($results) {
//fetch results set as object and output HTML
while($obj = $results-fetch_object())
{
echo 'div class="product"';
echo 'form method="post" action="cart_update.php"';
echo 'div class="product-thumb"img src="images/'.$obj-product_img_name.'"/div';
echo 'div class="product-content"h3'.$obj-product_name.'/h3';
echo 'div class="product-desc"'.$obj-product_desc.'/div';
echo 'div class="product-info"';
echo 'Price '.$currency.$obj-price.' | ';
echo 'Qty input type="text" name="product_qty" value="1" size="3" /';
echo 'button class="add_to_cart"Add To Cart/button';
echo '/div/div';
echo 'input type="hidden" name="product_code" value="'.$obj-product_code.'" /';
echo 'input type="hidden" name="type" value="add" /';
echo 'input type="hidden" name="return_url" value="'.$current_url.'" /';
echo '/form';
echo '/div';
}
}
?
/div
div class="shopping-cart"
h2Your Shopping Cart/h2
?php
if(isset($_SESSION["products"]))
{
$total = 0;
echo 'ol';
foreach ($_SESSION["products"] as $cart_itm)
{
echo 'li class="cart-itm"';
echo 'span class="remove-itm"a href="cart_update.php?removep='.$cart_itm["code"].'return_url='.$current_url.'"×/a/span';
echo 'h3'.$cart_itm["name"].'/h3';
echo 'div class="p-code"P code : '.$cart_itm["code"].'/div';
echo 'div class="p-qty"Qty : '.$cart_itm["qty"].'/div';
echo 'div class="p-price"Price :'.$currency.$cart_itm["price"].'/div';
echo '/li';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '/ol';
echo 'span class="check-out-txt"strongTotal : '.$currency.$total.'/strong a href="view_cart.php"Check-out!/a/span';
echo 'span class="empty-cart"a href="cart_update.php?emptycart=1return_url='.$current_url.'"Empty Cart/a/span';
}else{
echo 'Your Cart is empty';
}
?
/div
cart_update.php
PHP Code
?php
session_start();
include_once("config.php");
//empty cart by distroying current session
if(isset($_GET["emptycart"]) $_GET["emptycart"]==1)
{
$return_url = base64_decode($_GET["return_url"]); //return url
session_destroy();
header('Location:'.$return_url);
}
//add item in shopping cart
if(isset($_POST["type"]) $_POST["type"]=='add')
{
$product_code = filter_var($_POST["product_code"], FILTER_SANITIZE_STRING); //product code
$product_qty = filter_var($_POST["product_qty"], FILTER_SANITIZE_NUMBER_INT); //product code
$return_url = base64_decode($_POST["return_url"]); //return url
//limit quantity for single product
if($product_qty 10){
die('div align="center"This demo does not allowed more than 10 quantity!br /a href=""Back To Products/a./div');
}
//MySqli query - get details of item from db using product code
$results = $mysqli-query("SELECT product_name,price FROM cart WHERE product_code='$product_code' LIMIT 1");
$obj = $results-fetch_object();
if ($results) { //we have the product info
//prepare array for the session variable
$new_product = array(array('name'=$obj-product_name, 'code'=$product_code, 'qty'=$product_qty, 'price'=$obj-price));
if(isset($_SESSION["products"])) //if we have the session
{
$found = false; //set found item to false
foreach ($_SESSION["products"] as $cart_itm) //loop through session array
{
if($cart_itm["code"] == $product_code){ //the item exist in array
$product[] = array('name'=$cart_itm["name"], 'code'=$cart_itm["code"], 'qty'=$product_qty, 'price'=$cart_itm["price"]);
$found = true;
}else{
//item doesn't exist in the list, just retrive old info and prepare array for session var
$product[] = array('name'=$cart_itm["name"], 'code'=$cart_itm["code"], 'qty'=$cart_itm["qty"], 'price'=$cart_itm["price"]);
}
}
if($found == false) //we didn't find item in array
{
//add new user item in array
$_SESSION["products"] = array_merge($product, $new_product);
}else{
//found user item in array list, and increased the quantity
$_SESSION["products"] = $product;
}
}else{
//create a new session var if does not exist
$_SESSION["products"] = $new_product;
}
}
//redirect back to original page
header('Location:'.$return_url);
}
//remove item from shopping cart
if(isset($_GET["removep"]) isset($_GET["return_url"]) isset($_SESSION["products"]))
{
$product_code = $_GET["removep"]; //get the product code to remove
$return_url = base64_decode($_GET["return_url"]); //get return url
foreach ($_SESSION["products"] as $cart_itm) //loop through session array var
{
if($cart_itm["code"]!=$product_code){ //item does,t exist in the list
$product[] = array('name'=$cart_itm["name"], 'code'=$cart_itm["code"], 'qty'=$cart_itm["qty"], 'price'=$cart_itm["price"]);
}
//create a new product list for cart
$_SESSION["products"] = $product;
}
//redirect back to original page
header('Location:'.$return_url);
}
?
view_cart.php
PHP Code
div class="view-cart"
?php
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION["products"]))
{
$total = 0;
echo 'form method="post" action="paypal-express-checkout/process.php"';
echo 'ul';
$cart_items = 0;
foreach ($_SESSION["products"] as $cart_itm)
{
$product_code = $cart_itm["code"];
$results = $mysqli-query("SELECT product_name,product_desc, price FROM cart WHERE product_code='$product_code' LIMIT 1");
$obj = $results-fetch_object();
echo 'li class="cart-itm"';
echo 'span class="remove-itm"a href="cart_update.php?removep='.$cart_itm["code"].'return_url='.$current_url.'"×/a/span';
echo 'div class="p-price"'.$currency.$obj-price.'/div';
echo 'div class="product-info"';
echo 'h3'.$obj-product_name.' (Code :'.$product_code.')/h3 ';
echo 'div class="p-qty"Qty : '.$cart_itm["qty"].'/div';
echo 'div'.$obj-product_desc.'/div';
echo '/div';
echo '/li';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
echo 'input type="hidden" name="item_name['.$cart_items.']" value="'.$obj-product_name.'" /';
echo 'input type="hidden" name="item_code['.$cart_items.']" value="'.$product_code.'" /';
echo 'input type="hidden" name="item_desc['.$cart_items.']" value="'.$obj-product_desc.'" /';
echo 'input type="hidden" name="item_qty['.$cart_items.']" value="'.$cart_itm["qty"].'" /';
$cart_items ++;
}
echo '/ul';
echo 'span class="check-out-txt"';
echo 'strongTotal : '.$currency.$total.'/strong ';
echo '/span';
echo '/form';
}else{
echo 'Your Cart is empty';
}
?
/div
/div
php网上购物查询代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php小型购物网站源码、php网上购物查询代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-11自助建站系统源码,自助建站源码php
- 05-11购物网站排名,最火的电商平台排行榜
- 05-11关键词指数批量查询,百度关键词指数批量查询
- 05-10小红书指数,小红书指数查询
- 05-09网页代码,网页代码快捷键
- 05-08站长之家,备案查询站长之家
- 05-08网站访问量查询工具,网站访问量统计
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接