doufeiqiong3515 2018-07-19 18:01
浏览 71

如何获取会话ID并将其插入到产品ID旁边的数据库中

I am trying to get session id from a user that logs in and insert it into database next to id of a product that user ordered. I'm new to php, so i dont know how to get this id, it somehow always shows 0 in database. Here is the code:

This is the starting code of the page, session is supposed to be taken from a login.inc.php file

    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']);

Here is the code that should insert products into table 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);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大