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

如何将产品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

有两个表; 一个用于产品详细信息 strong>,第二个用于产品图片 strong>。 p>

第一页是产品详细信息 em>和 产品详情页面插入 em>产品详细信息。 那么如何获取最近插入的产品的ID并将该ID重定向到另一个页面以插入该产品图像? p>

我想将产品ID从一个页面传递到另一个页面以便插入 该产品图片。 p>

id可以通过url但我不知道如何传递它。 p>

两个表的产品都不同 详细信息和产品图片。 p>

请提供代码。 p>

在此页面中插入的产品详细信息和我想通过的最近插入产品的ID 在另一页: p>

p>

我想要产品ID: p> \ n

p> div>

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
}


?>

You can use $last_id = $conn->insert_id;in plain PHP.

While in laravel you can use insertGetId() function to get the id of last inserted Item.

And retrieve the last_id in other page by using $last_id=$_GET['id'] if method is get or $last_id=$_POST['id'] if method is post.

i think you can use php sessoins and pass the values to next pages and also don't forget to kill the session once u finished.

  <?php
  session_start();
  $_SESSION["Product_id"] = your id;
  $_SESSION["Product_iamge"] = your image url;
  ?>