首页 > 解决方案 > 会话在锚标记中不起作用

问题描述

我将会话传递到循环中的下一页,在那里我得到不同的 $post_id 值,但它似乎取 1 个值,并且没有改变。

<?php
include('dataconnect.php');
$conn = new mysqli($servername, $username, $password, $dbname); 
if ($conn->connect_error) {
    die("Connection failed: " .$conn->connect_error);
}                   
$sql = "SELECT * FROM user";
$result = $conn->query($sql);
if ($result->num_rows > 0) { 
    while($row = $result->fetch_assoc()) { 
        $post_id = "{$row['id']}"; 
        ?>

        <a href="comment.php?<?php $_SESSION['user_id'] = intVal($post_id);  ?>" >Comment</i></a>

    <?php } 
}  
$conn->close(); 
?>

标签: javascriptphp

解决方案


i changed this, hope this help!

 <a href="comment.php?session=<?php echo $_SESSION['user_id'] = intVal($post_id);  ?>" >Comment</i></a>

推荐阅读