doulu1968 2013-04-11 15:20
浏览 116

将数据插入到购物车的数据库中

I am doing a shopping cart and I am not sure where or rather which page do I code my INSERT INTO statement.

viewProducts.php

 <?php
            if (isset($_SESSION['cartCity'])) {
                $sql = "SELECT * FROM productsc WHERE id_product IN (";
                foreach ($_SESSION['cartCity'] as $id => $value) {
                    $sql .= $id . ",";
                }
                $sql = substr($sql, 0, -1) . ") ORDER BY id_product ASC";
                $query = mysql_query($sql);
                if (!empty($query)) {
                    while ($row = mysql_fetch_assoc($query)) {
                        ?>
                        <p><?php echo $row['name']; ?><?php echo " x " . $_SESSION['cartCity'][$row['id_product']]['quantity']; ?></p>

                        <?php
                    }
                   } else {
                    echo "<i>You need to add an item to your cart for it to be visible here</i><br />";
                }
            } else {
                echo "<p>Your cart is empty. <br/> Please add some products</p>";
            }
            echo "<a href='viewProductsCity.php?page=cartCity'>Go to Cart</a>";
            echo "<a href='checkout.php'>Checkout</a>";
            ?>

or should i add in cart or viewAdd(this is where the codes for when the customer clicks on add to cart button runs) page?

  • 写回答

1条回答 默认 最新

  • doupo2241 2013-04-11 15:24
    关注

    I would create a separate page to do that.

    Then, I would include it just by redirecting the user there or by calling it with AJAX. When user got the cart with something, then yeah, we would redirect him to the checkout, and ask him if he wants to buy now or keep shopping.

    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False