duanlu7680 2018-04-02 04:58
浏览 35

将我的购物车表加入我的客户表

I want to join my cart table to my customer table, so I can add the product_quantity table to prevent users from inputting higher number than the quantity of the product. For me, this can be a way to make this work. Thanks

This is my add_cart.php

<?php

        include('session.php');
        if(isset($_POST['cart'])){
            $id=$_POST['id'];
            $qty=$_POST['qty'];


            $query=mysqli_query($conn,"select * from cart where productid='$id' and userid='".$_SESSION['id']."'");


            if (mysqli_num_rows($query)>0){
                echo "Product already on your cart!";

    }

            else{
                mysqli_query($conn,"insert into cart (userid, productid, qty) values ('".$_SESSION['id']."', '$id', '$qty')");
            }

        }

    ?>

This is my product table.

PRODUCT TABLE

This is my cart table.

Cart Table

  • 写回答

2条回答 默认 最新

  • duancong7573 2018-04-02 05:04
    关注

    You can try to use INNER JOIN to link two table by productid

    select * from cart 
    INNER JOIN product ON cart.productid = product.productid
    where cart.productid='$id' and userid='".$_SESSION['id']."'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计