<?php
include 'config.php'; //connect to db
if(isset($_REQUEST["pwd"]) && isset($_REQUEST["name"])) {
$password = $_REQUEST['pwd']; //pass from previous page
$name = $_REQUEST['name']; //pass from previous page
$checkUserPass = mysql_query("SELECT * FROM validPersonnel WHERE Passkey = '$password' and Name = '$name'", $conn); //check if the user exist
if(mysql_num_rows($checkUserPass) == 1) {
$personnelId = mysql_query("SELECT PersonnelID FROM validPersonnel WHERE Passkey = '$password' and Name = '$name'", $conn); //query user id
while($row = mysql_fetch_assoc($personnelId)) {
echo $row['PersonnelD']; // print user id
}
mysql_close($conn);
//echo "<br/><br/>";
//echo "<script>alert('Logged In.')</script>";
//header("Refresh: 1; url=profile/profile.php?id="'.$id.');
//header('Refresh: 1; url=test.php?id=$personnelId');
} else {
echo "<br/><br/>";
echo "<script>alert('Wrong Password.')</script>";
header('Refresh: 1; url=personnelselect.php');
}
}
?>
我无法echo
$row['PersonnelD']
页面显示为空白。我无法理解我哪里出错了。这个页面的问题已经解决了
答案 0 :(得分:3)
看起来你的代码有误:
echo $row['PersonnelD'];
不应该跟随吗?
echo $row['PersonnelID'];
答案 1 :(得分:1)
答案 2 :(得分:-1)
尝试使用var_dump()
函数调试并检查变量中的值。例如:var_dump($row);
在while循环中。
答案 3 :(得分:-2)
在您的两个查询中,您都有
"SELECT * FROM validPersonnel WHERE Passkey = '$password' and Name = '$name'"
应该是:
"SELECT * FROM validPersonnel WHERE Passkey = '".$password."' and Name = '".$name."';"
除非您关闭引号,否则PHP无法识别$ var。句点将$ var添加到字符串中。