dth34653 2017-12-06 10:33
浏览 34
已采纳

如何获取数据并在PHP中使用id插入?

I make shopping site in php and I have one issue of product data.

First I make **product** datatabe below.

    CREATE TABLE IF NOT EXISTS `product` (                                    
       `product_id` int(11) NOT NULL AUTO_INCREMENT,                               
       `product_sales_id` int(11) NOT NULL,                                        
       `product_name` varchar(100) NOT NULL,                                        
       `product_price` varchar(5000) NOT NULL,                                       
       `image_name` varchar(300) NOT NULL,                                               
       PRIMARY KEY (`product_id`)
    )


And Second table **product sales** below :

    CREATE TABLE IF NOT EXISTS `product_sales` (                                  
       `product_sales_id` int(11) NOT NULL,                                          
    )

Below page it admin site page when select product to insert in database and 
show in product page.

Add_Product.php : 

    <?php 
        include_once('include/connection.php');
        include_once('include/function.php');
    ?>

    <?php 
        if(isset($_POST['submit'])){
            $product_name = mysqli_real_escape_string($conn,$_POST['product_name']);
            $product_price = mysqli_real_escape_string($conn,$_POST['product_price']);  
            $image_name = mysqli_real_escape_string($conn, basename( $_FILES["product_image"]["name"]));

            $target_dir = "upload/";
            $target_file = $target_dir . basename($_FILES["product_image"]["name"]);
            $uploadOk = 1;
            $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
            $filetype = $_FILES["product_image"]["type"];

            $image_upload = move_uploaded_file($_FILES["product_image"]["tmp_name"], $target_file);

            if($image_upload){
                mysqli_query($conn,"INSERT INTO product(product_name,product_price,image_name) VALUES ('".$product_name."','".$product_price."','".$image_name."')");   
            }

        }
    ?>

I make on more page product sell page but i do not know how to make this Above show I make table product_sales and his id store in product table how to add product_sales in database and show in page using id through.

  • 写回答

2条回答 默认 最新

  • duanpi5733 2017-12-06 10:47
    关注

    Change the product_sales_id in product_sales table into primary key and add product_id field as a foreign key in product_sales table.

    Once the product is sold, you can store the product_id in the product_sales table.

    And you can fetch the sold product details from product table using product_id which is present in the product_sales table using join query.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示