为什么我的购物车内容未显示在Justhost Server上但显示在本地服务器上?

时间:2016-09-29 18:08:44

标签: php html5 e-commerce shopping-cart cart

我有一个php购物车,它使用cookies来记住用户的物品。

它在我的本地wamp服务器上工作正常,我添加或删除项目并在我的购物车中查看它们。但是,当我将网站上传到JustHost以查看它在网上的样子时,我仍然可以将商品添加到购物车并查看产品页面,但是当我点击购物车查看我在购物车中的内容时,我只能看到我的导航栏,我的页脚也被破坏了,导航栏中的下拉菜单无法正常工作。

以下是我购物车页面的代码:

<?php
$page_title="Cart";
include '/includes/header.php';
include './config/config.php';

$action = isset($_GET['action']) ? $_GET['action'] : "";
$name = isset($_GET['name']) ? $_GET['name'] : "";

if($action=='removed'){
echo "<div class='alert alert-info'>";
    echo "<strong>{$name}</strong> was removed from your cart!";
echo "</div>";
}

$cookie = $_COOKIE['cart_items_cookie'];
$cookie = stripslashes($cookie);
$saved_cart_items = json_decode($cookie, true);

if(count($saved_cart_items)>0){
// get the product ids
$ids = "";
foreach($saved_cart_items as $id=>$name){
    $ids = $ids . $id . ",";
}

// remove the last comma
$ids = rtrim($ids, ',');

//start table
echo "<table class='table table-hover table-responsive table-bordered'>";

    // our table heading
    echo "<tr>";
        echo "<th class='textAlignLeft'>Product Name</th>";
        echo "<th>Price (USD)</th>";
        echo "<th>Action</th>";
    echo "</tr>";

    $query = "SELECT id, name, price FROM products WHERE id IN ({$ids})     ORDER BY name";
    $stmt = $con->prepare( $query );
    $stmt->execute();

    $total_price=0;
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);

        echo "<tr>";
            echo "<td>{$name}</td>";
            echo "<td>&#36;{$price}</td>";
            echo "<td>";
                echo "<a href='remove_from_cart.php?id={$id}&name={$name}' class='btn btn-danger'>";
                    echo "<span class='glyphicon glyphicon-remove'></span> Remove from cart";
                echo "</a>";
            echo "</td>";
        echo "</tr>";

        $total_price+=$price;
    }

    echo "<tr>";
            echo "<td><b>Total</b></td>";
            echo "<td>&#36;{$total_price}</td>";
            echo "<td>";
                echo "<a href='payment-page.php' class='btn btn-success'>";
                    echo "<span class='glyphicon glyphicon-shopping-cart'></span> Checkout";
                echo "</a>";
            echo "</td>";
        echo "</tr>";

echo "</table>";
}

else{
echo "<div class='alert alert-danger'>";
    echo "<strong>No products found</strong> in your cart!";
echo "</div>";
}

include 'includes/footer.php';
?>

请有人可以告知我的购物车页面代码是否遗漏了某些内容(或者我是否应该在其他文件中添加内容...),这会阻止我在查看此页面时看到任何内容

感谢您的帮助

0 个答案:

没有答案