doujuan9698 2018-03-14 10:30
浏览 33
已采纳

如何将产品ID从一个页面传递到另一个页面,以便在PHP中插入该产品的图像?

There are two tables; one for product details and the second for product images.

The first page is product detail and product details page insert the product details. So how to fetch the id of that recent inserted product and that id redirect to another page for insertion of that product image?

I want to pass product id from one page to another page for insertion of that product image.

The id can pass through url but I don't know how to pass it.

Both tables are different for product detail and product image.

Please provide code for it.

In this page product detail inserted and id of this recent inserted product I want to pass in another page:

enter image description here

I want the product id here:

enter image description here

  • 写回答

3条回答 默认 最新

  • douzi5214 2018-03-14 10:40
    关注

    product-details.php

    <?php
    
    $result = mysqli_query($connection, $some_insert_query_here);
    if($result){
         $lastId = mysqli_insert_id($connection);
         header("Location: product-image.php?id=".$lastId);
    }
    ?>
    

    product-image.php

    <?php
    
    if(isset($_GET['id'])){
         $lastId = $_GET['id'];
         // do stuff with this last inserted product id
    }
    
    
    ?>
    

    or try sessions:

    product-details.php

    <?php
    
        $result = mysqli_query($connection, $some_insert_query_here);
        if($result){
             $lastId = mysqli_insert_id($connection);
    
             session_start();
             $_SESSION['last_id']  = $lastId;
             header("Location: product-image.php");
        }
        ?>
    

    product-image.php

    <?php
    session_start();
    if(isset($_SESSION['last_id'])){
    
         $lastId = $_SESSION['last_id'];
         // do stuff with this last inserted product id
    }
    
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 nrf52810-c三个a 程序
  • ¥15 lego-loam跑出来的roll误差很大
  • ¥50 求一个半透明没有锯齿的圆角窗体的实现例子
  • ¥15 STM32cubeMX里的FreeRTOS无法释放内存
  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对