我正在尝试从登录的用户那里获取会话ID,并将其插入数据库中用户订购的产品ID旁边。我是php新手,所以我不知道如何获取此id,它总是以某种方式在数据库中显示0。这是代码:
这是页面的起始代码,会话应来自login.inc.php文件
session_start();
include "includes/dbh.inc.php";
$id = isset($_GET['id']) ? $_GET['id'] : '';
$sql = "SELECT * FROM tbl_product WHERE id = ". $id;
$result = mysqli_query($conn, $sql);
$u_id = isset($_SESSION['u_id']);
下面是将产品插入到表user_korpa中的代码
if (isset($_POST['dodajukorpu'])) {
while ($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
$name = $row['name'];
$image = $row['image'];
$price = $row['price'];
$tip = $row['tip_proizvoda'];
$sql = "INSERT INTO user_korpa (p_id, u_id, name, image, price, tip_proizvoda) VALUES ('$id','{$_SESSION['u_id']}','$name','$image','$price','$tip')";
$result2 = mysqli_query($conn, $sql);