我在 tblStudentDetails 中有两个条目具有 RollNo = 0 和 1 但是每当我尝试从数据库中检索数据时,我总是得到第一条记录,即 RollNo = 0 这是我的代码:
<?php
unset($_SESSION['RollNo']);
unset($_SESSION['StudentName']);
unset($_SESSION['Course']);
include_once 'Includes/DBConnection.php';
//echo $_POST['txtRollNo'];
if ($_POST['btnSubmit'] == 'Submit')
{
if ($_POST['txtRollNo'] != '')
{
$query = "SELECT StudentName, Course FROM tblStudentDetails WHERE RollNo = '$_POST[txtRollNo]'";
$result = mysql_query($query);
$rowCount = mysql_num_rows($result);
if ($rowCount == 0)
{
echo "You have entered an incorrect roll No";
//header ('Location: index.php');
}
else
{
while ($row = mysql_fetch_assoc($result))
{
$StudentName = $row['StudentName'];
$Course = $row['Course'];
}
$_SESSION['RollNo'] = $_POST['txtRollNo'];
$_SESSION['StudentName'] = $StudentName;
$_SESSION['Course'] = $Course;
header ('Location: SelectedUserDetails.php');
}
}
else
{
echo "Please Enter Your Roll No.";
//header ('Location: index.php');
}
}
?>
<html>
<head>
<title>Online Exam</title>
<STYLE TYPE = "Text/CSS">
H1
{
Color : DodgerBlue;
Text-Align : Center
}
HR
{
Color : DodgerBlue
}
LABEL
{
Vertical-Align : Bottom;
Font-Size : 20
}
TR
{
Height : 30;
Background : White;
Color : Black;
Font-Size : 20
}
</STYLE>
</head>
<BODY BGCOLOR = "BLACK" TEXT = "WHITE">
<CENTER>
<TABLE ALIGN = "CENTER">
<TR>
<?php include 'Includes/header.html'; ?>
</TR>
<TR>
<TD>
<TABLE>
<TR>
<FORM NAME = "frmMain" METHOD = "POST" ACTION = "<?php echo $PHP_SELF ?>" enctype = "multipart/form-data">
<TD>
Enter your roll no. :
</TD>
<TD>
<INPUT TYPE = "TEXT" NAME = "txtRollNo" />
</TD>
<TD>
<INPUT TYPE = "SUBMIT" NAME = "btnSubmit" VALUE = "Submit" />
</TD>
</FORM>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</html>
在 SelectedUserPage 我试图检查的值,$_SESSION['RollNo']
但它始终为空。谁能说出上面代码中的问题是什么?