我在下面有这个代码,我似乎无法理解为什么我在下一页看不到$ pId。我好像他没有在profile.php中的$ pId中发送变量请帮助
<?php
include 'config.php';
include 'dbconnection.php';
session_start();
if(isset($_REQUEST["pwd"]) && isset($_REQUEST["name"]))
{
$password = $_REQUEST['pwd'];
$name = $_REQUEST['name'];
$checkUserPass = mysql_query("SELECT * FROM validPersonnel WHERE Passkey = '$password' and Name = '$name'", $conn);
if(mysql_num_rows($checkUserPass) == 1)
{
$sql="SELECT PersonnelID FROM validPersonnel WHERE Passkey = :password and Name = :name";
$query=$db->prepare($sql);
$query->execute(array('name' => $name, 'password' => $password));
$row = $query->fetch();
$_SESSION['personnelId'] = $row['PersonnelID'];
header("Refresh: 1; url=profile/profile.php?p_id={$pId}");
echo "<br/><br/>";
echo "<script>alert('Logged In.')</script>";
}
else
{
// print_r($query);
echo "<br/><br/>";
echo "<script>alert('Wrong Password.')</script>";
header('Refresh: 1; url=personnelselect.php');
}
}
mysql_close($conn);
?>
下面的代码是我传递$ pId的链接
if(isset($_SESSION['personnelId']))
{
$id = $_SESSION['personnelId'];
$sqlLoader="Select Name from validpersonnel where PersonnelID = :id";
$resLoader=$db->prepare($sqlLoader);
$resLoader->execute(array('id' => $id));
$row = $resLoader->fetch();
echo $row['Name'];
}
?>
答案 0 :(得分:0)
脚本结束时几乎所有变量都被销毁。我建议使用$ _SESSION变量或通过$ _GET传递变量。
例如存储变量:
$_SESSION['pid'] = $pId;
检索变量:
if (isset($_SESSION['pid'])) $pId = $_SESSION['pid'];