Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重定向在live server上不起作用_Php_Html_Shopping Cart - Fatal编程技术网

Php 重定向在live server上不起作用

Php 重定向在live server上不起作用,php,html,shopping-cart,Php,Html,Shopping Cart,这是指向测试域上站点的链接 我遇到的问题是从购物车中删除一个项目。一切都可以在我的本地主机上运行,但当我将其上传到live server时,“从购物车中删除项目”停止工作。谁能告诉我哪里出了问题。谢谢你的团队 <?php include_once("../php/cart_config.php"); session_start(); //add item in shopping cart if(isset($_POST["type"]) &&am

这是指向测试域上站点的链接

我遇到的问题是从购物车中删除一个项目。一切都可以在我的本地主机上运行,但当我将其上传到live server时,“从购物车中删除项目”停止工作。谁能告诉我哪里出了问题。谢谢你的团队

<?php
    include_once("../php/cart_config.php");
    session_start();


    //add item in shopping cart
    if(isset($_POST["type"]) && $_POST["type"]=='add')
    {
        $product_code   = filter_var($_POST["product_code"], FILTER_SANITIZE_STRING); //product code
        $return_url     = base64_decode($_POST["return_url"]); //return url

        //MySqli query - get details of item from db using product code
        $results = $mysqli->query("SELECT product_name,price FROM products 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'=>1, '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
                        $qty = $cart_itm["qty"]+1; //increase the quantity
                        $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$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 exist in the list

                //continue only if quantity is more than 1
                //removing item that has 0 qty
                if($cart_itm["qty"]>1) 
                {
                $qty = $cart_itm["qty"]-1; //just decrese the quantity
                //prepare array for the products session
                $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$qty, 'price'=>$cart_itm["price"]);
                }

            }else{
                $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]);
            }

            //set session with new array values
            $_SESSION["products"] = $product;
        }
        //redirect back to original page
        header('Location:'.$return_url);
    }
    ?>

如果已显示HTML,则无法输出PHP标头。您可以改用Javascript

?>
 <script type="text/javascript">
   window.location = "<?php echo $return_url; ?>";
 </script>
<?php
?>
window.location=“”;

转到php/cart_update.php并在此处发布源代码。:)@哈桑:我上面粘贴的代码是cart_update.php,但是现在你建议我做什么来停止flash加载?你建议ajax吗?或者angularJS?如果你不想在页面加载时使用flash,你需要用Ajax创建一个页面处理程序,听起来像是一个计划,你知道有什么文章可以帮我创建它吗?那么为什么可以使用它向购物车添加一个项目我不明白为什么标题('Location:'。$return\u url);从购物车中移除物品时不起作用这怎么可能??