购物车的浏览器兼容性问题
程序员文章站
2022-05-23 14:31:59
...
从网上找了个购物车,挺好用的,简单方便,可就是存在一个问题:不兼容IE6/IE7,点击“添加购物车”按钮没反应,而内网又存在大量的IE6,我看了一下,应该是html的兼容性问题,但就是找不到问题出在哪,大家帮忙看看:
购物车主程序:cart.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']);
require_once 'class/config.db.php';
require_once 'class/db.php';
$db=new db();
$results = $db->query("SELECT * FROM cart ORDER BY id ASC");
if ($results) {
//fetch results set as object and output HTML
while($obj = $db->fetch_object($results))
{
echo '
}
}
?>
if(isset($_SESSION["products"]))
{
$total = 0;
echo '
echo 'Total : '.$currency.$total.' Check-out!';
echo 'Empty Cart';
}else{
echo 'Your Cart is empty';
}
?>
提交按钮的链接,点按钮没反应。cart_update.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('
}
//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);
}
?>
解决了,是submit的事
购物车主程序:cart.php:
Products
//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']);
require_once 'class/config.db.php';
require_once 'class/db.php';
$db=new db();
$results = $db->query("SELECT * FROM cart ORDER BY id ASC");
if ($results) {
//fetch results set as object and output HTML
while($obj = $db->fetch_object($results))
{
echo '
';
echo '';
echo '
'; echo '';
echo '
}
}
?>
Your Shopping Cart
if(isset($_SESSION["products"]))
{
$total = 0;
echo '
- ';
- ';
echo '×';
echo ''.$cart_itm["name"].'
';
echo 'P code : '.$cart_itm["code"].'';
echo 'Qty : '.$cart_itm["qty"].'';
echo 'Price :'.$currency.$cart_itm["price"].'';
echo ' ';
foreach ($_SESSION["products"] as $cart_itm)
{
echo '
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '
echo 'Total : '.$currency.$total.' Check-out!';
echo 'Empty Cart';
}else{
echo 'Your Cart is empty';
}
?>
提交按钮的链接,点按钮没反应。cart_update.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('
This demo does not allowed more than 10 quantity!
Back To Products.
'); Back To Products.
}
//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);
}
?>
回复讨论(解决方案)
你的表单没有提交按钮,且没有给出通过 js 提交的代码
所以任何浏览器都不可能产生表单提交动作
你的表单没有提交按钮,且没有给出通过 js 提交的代码
所以任何浏览器都不可能产生表单提交动作
解决了,是submit的事
上一篇: 数据库连接技术之OLEDB
下一篇: 初探nginx架构
推荐阅读
-
js与jQuery实现的兼容多浏览器Ajax请求实例
-
div+css布局时的浏览器兼容问题_html/css_WEB-ITnose
-
善用抓包软件fiddler解决discuz中图片上传浏览器兼容性问题
-
经常遇到的浏览器兼容性问题_html/css_WEB-ITnose
-
兼容主流浏览器的jQuery+CSS 实现遮罩层的简单代码
-
谈谈JS中常遇到的浏览器兼容问题和解决方法
-
代码非常简洁且兼容多浏览器的拖动层实现代码
-
CSS实现的兼容所有浏览器的div悬浮在网页一侧的代码_html/css_WEB-ITnose
-
div+csS中的一些技巧和浏览器兼容的办法_html/css_WEB-ITnose
-
CSS实现的兼容所有浏览器的div悬浮在网页一侧的代码_html/css_WEB-ITnose