繁体   English   中英

PHP的购物车不显示购物车中的项目?

[英]php shopping cart not displaying items in cart?

我正在尝试在我的网站上实施php购物车。 我目前有正确从我的数据库中读取的产品页面。 当购物车为空时,将显示“您的购物车中没有物品”文本,但是,当购物车中有东西时,它将显示该表的标题,但没有产品信息。

<form name="cartform" method="post" action="">
        <input type="hidden" name="productid" />
        <input type="hidden" name="command" />
        <span id="cont_shop">
        <input type="button" value="Continue Shopping" onclick="window.location.href='../Project/products.php'" />
        </span>
        <div id="formerror"><?php echo $message ?></div>

        <table id="cart_table">
        <?php
            if(count($_SESSION['cart']))
            {
                echo '<tr>
                <th>Name</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Amount</th>
                <th>Options</th>
                </tr>';

                $max = count($_SESSION['cart']);

                for($i = 0; $i < $max; $i++)
                {
                    $product_id = $_SESSION['cart'][$i]['productid'];
                    $quantity = $_SESSION['cart'][$i]['quantity'];
                    $product_name = get_product_name($dbc,$product_id);
                    $product_price = get_price($dbc,$product_id);

                    if($quantity == 0)
                    {
                        continue;
                    }

                    echo '<tr>
                    <td>' . $product_name . '</td>
                    <td>&#36; ' . $product_price . '</td>
                    <td><input type="text" name="product' . $product_id . '" value="' . $quantity . '" maxlength="4" size="2" /></td>
                    <td>&#36; ' . $product_price*$quantity . '</td>
                    <td><a href="javascript:del(' . $product_id . ')">Remove Item</a></td>
                    </tr>';
                }

                echo '<tr>
                <td colspan="2"><strong>Order Total: &#36;' . get_order_total($dbc) . '</strong></td>
                <td></td>
                <td colspan="3" id="cart_buttons">
                <input type="submit" value="Clear Cart" onclick="clear_cart()">
                <input type="submit" value="Update Cart" onclick="update_cart()">
                <input type="submit" value="Complete Order" onclick="complete_order()">
                </td>
                </tr>';
            }

            else
            {
                echo '<tr><td>There are no items in your shopping cart.</td></tr>';
            }
        ?>
        </table>
        </form>

当我查看页面源代码时,所看到的只是此处的HTML渲染:

    <table id="cart_table">
    <tr>
            <th>Name</th>
            <th>Price</th>
            <th>Quantity</th>
            <th>Amount</th>
            <th>Options</th>
            </tr>
   <?php
     if(count($_SESSION['cart']))
            { 
   ?>
      <form name="cartform" method="post" action="">
        <input type="hidden" name="productid" />
        <input type="hidden" name="command" />
        <span id="cont_shop">
          <input type="button" value="Continue Shopping" onclick="window.location.href='../Project/products.php'" />
        </span>
        <div id="formerror"><?php echo $message ?></div>

        <table id="cart_table">
        <?php

                echo '<tr>
                <th>Name</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Amount</th>
                <th>Options</th>
                </tr>';

                $max = count($_SESSION['cart']);

                for($i = 0; $i < $max; $i++)
                {
                    $product_id = $_SESSION['cart'][$i]['productid'];
                    $quantity = $_SESSION['cart'][$i]['quantity'];
                    $product_name = get_product_name($dbc,$product_id);
                    $product_price = get_price($dbc,$product_id);

                    if($quantity == 0)
                    {
                        continue;
                    }

                    echo '<tr>
                    <td>' . $product_name . '</td>
                    <td>&#36; ' . $product_price . '</td>
                    <td><input type="text" name="product' . $product_id . '" value="' . $quantity . '" maxlength="4" size="2" /></td>
                    <td>&#36; ' . $product_price*$quantity . '</td>
                    <td><a href="javascript:del(' . $product_id . ')">Remove Item</a></td>
                    </tr>';
                }

                echo '<tr>
                <td colspan="2"><strong>Order Total: &#36;' . get_order_total($dbc) . '</strong></td>
                <td></td>
                <td colspan="3" id="cart_buttons">
                <input type="submit" value="Clear Cart" onclick="clear_cart()">
                <input type="submit" value="Update Cart" onclick="update_cart()">
                <input type="submit" value="Complete Order" onclick="complete_order()">
                </td>
                </tr>';
             ?>
         </table>
         </form>
      <?php
         }

            else
            {
                echo '<tr><td>There are no items in your shopping cart.</td></tr>';
            }
        ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM