2014-02-21 42 views
0

這是鏈接到該網站上測試域Domain Link重定向不工作現場服務器【解析】

有從購物車移除項目的問題IM。一切工作在我的本地主機,但只要我上傳到現場服務器刪除項目從購物車停止工作。有人可以告訴我哪裏會出錯。感謝團隊。

<?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); 
    } 
    ?> 
+0

轉到php/cart_update.php並在此處發佈源代碼。 :) – Hassan

+0

@hassan:我上面粘貼的代碼是cart_update.php老兄 – Code

回答

0

如果已經顯示HTML,則不能輸出PHP標頭。您可以使用JavaScript代替。

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

這樣做也一樣,但它會一直工作!

+0

非常感謝你是KING很好的一個 – Code

+0

但是現在你會怎麼建議我停止閃存加載你會提示ajax?或者angularJS? – Code

+0

如果你不想在頁面加載的Flash,你需要創建一個頁面處理程序與AJAX –

相關問題