dqqt31923 2014-03-09 03:37
浏览 20

会话不使用正确的变量

I have a session that is supposed to carry a variable from one page to another. The session is set, however it does not have the correct value, I need this session to dynamically change. Here's the code for the viewing page:

  // Connect to the database
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

      $query = "SELECT username FROM kaoscraft_user WHERE user_id = '" . $_SESSION['user_id'] . "'";
        $data = mysqli_query($dbc, $query);
            $row = mysqli_fetch_array($data);
            $username1 = $row['username'];

  // Grab the pm data from the database
  $query = "SELECT `to`, `from`, rank, gender, picture, title, msg FROM kaoscraft_pm WHERE `to` = '$username1' ORDER BY msg_id DESC";
  $data = mysqli_query($dbc, $query);
  $gender = $row['gender'];

  while ($row = mysqli_fetch_array($data)) {
  session_start();
    $reply = $row['from'];
    $_SESSION['reply'] = $row['from'];
  echo '<div class="viewpost">';
  echo '<div class="vpside">';
    if(!empty($row['picture'])) {
    echo '<img class="pictest" src="' . MM_UPLOADPATH . $row['picture'] . '" alt="' . MM_UPLOADPATH . 'nopic.png' . '" />';
    }
  if(!empty($row['from'])) {
      echo '<p>From:<br />' . $row['from'] . '</p>';
      echo '<a href="reply.php">Reply</a>';
    }
  if(!empty($row['rank'])) {
      echo '<p>Rank:<br />' . $row['rank'] . '</p>';
    }
  if(!empty($row['gender'])){
    echo '<p>Gender:<br /> ' . $row['gender'] . '</p>';
  }  
  echo '</div>';

    if(!empty($row['title'])) {
        echo'<h4><u>' .$row['title']. '</u></h4>';
    }
      if(!empty($row['msg'])) {
      echo '<p class="">' . $row['msg'] . '</p>';
    }
        echo '<div class="sig">';
      if(!empty($row['bio'])) {
      echo '<p>' . $row['bio'] . '</p>';
      }
      echo '</div>';
    echo '</div><br />'; 
    }
  mysqli_close($dbc); 
?>

Yes, the query had been executed, and yes row is set.

Here's the carry over script:

    if (isset($_SESSION['reply'])) {
    echo 'value=' . $_SESSION['reply'];
    }

Mind you this is a test script and not the script I will actually be using, just in-case you were wondering. and in the second script it is a SNIPPET not the whole code that is why you do not see session_start();

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c