对如何正确使用SESSIONS感到困惑?对于PHP& MySQL的

时间:2014-07-01 09:01:53

标签: php mysql session

我对会议的运作方式感到困惑。我正在使用GET函数并使用Sessions,但似乎我被卡住了。即使我点击其他部门,我的返回值也不会改变。

<?php
session_start();
while ($row = mysqli_fetch_assoc($select_submission_result)) {
    $adopt_id = $row['a_id'];
    $promote_id = $row['p_id'];

    $adopt_dept = $row['a_department'];
    $promote_dept = $row['p_department'];

    echo "<tr>";
    echo "<td>";
    echo $i++;
    echo "</td>";

    echo "<td>";
    echo "<a href ='ideaSubmission.php?a_id = $adopt_id' style='color:     black; text-decoration: none;'>" . $row['a_title'] . "</a>";
    echo "</td>";
    echo "<td>";
    echo "<a href ='viewDepartment.php?a_department = $adopt_dept' style='color: black; text-decoration: none;'>" . $row['a_department'] . "</a>";
    echo "</td>";

    echo "<td>";
    echo "<a href ='ideaSubmission.php?p_id = $promote_id' style='color: black; text-decoration: none;'>" . $row['p_title'] . "</a>";
    echo "</td>";

    echo "<td>";
    echo "<a href ='viewDepartment.php?p_department = $promote_dept' style='color: black; text-decoration: none;'>" . $row['p_department'] . "</a>";
    echo "</td>";

    echo "</tr>";
}

$_SESSION['a_department'] = $_GET[$adopt_dept];
?>

我点击了指向 viewDepartment.php 的超链接,而它指向的另一个页面是:

<?php
session_start();

if (isset($_GET['a_department'])) {
$adopt_dept = $_GET['a_department'];
} else {`enter code here`
echo"not working";
 }
?>
<?php echo "$adopt_dept"; ?>

1 个答案:

答案 0 :(得分:0)

你应该检查会话而不是get:

<?php
session_start();
$adopt_dept = '';
if (isset($_SESSION['a_department'])) {
   $adopt_dept = $_SESSION['a_department'];
 } else {
   echo"not working";
 }
?>
<?php echo $adopt_dept ?>