如何使用会话功能反映登录表单的正确用户以显示他/她的用户ID?目前,在我们希望Admin no字段显示登录学生的用户ID的表单上没有反映任何内容。
<?php session_start();
$adminName = $_SESSION['txtName'];
$adminPassword = $_SESSION['txtPassword'];
?>
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' type='text/css' href='css/menupanel.css' />
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'> </script>
<div id="header">
<p align="center"><img src="images/logo.png" width="329" height="119" alt="TP Logo" /><br /></p>
</div>
</head>
<body>
<?php
include_once ('studentmenu.php');
$con=mysqli_connect("","","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(! get_magic_quotes_gpc() )
{
$address = $_POST['address'];
$GPA = $_POST['GPA'];
$result = mysqli_query($con, "SELECT name FROM student_details;");
$row = mysqli_fetch_assoc($result);
$result2 = mysqli_query($con, "SELECT admin_no FROM student_details;");
$row2 = mysqli_fetch_assoc($result2);
$result3 = mysqli_query($con, "INSERT INTO student_details"."(address,GPA)"."VALUES('$address','$GPA;");
}
?>
<p>
<table border="1">
<tr>
<td width="410" align="center">Student Personal Data</td>
</tr>
<tr>
<td height="170">
<table>
<form method= "post" action="studentpers_now.php">
<tr>
<td>Admission Number</td>
<td><input name="Admin_no" type= "text" disabled="disabled" value=<?php echo $_SESSION['txtName'] ?>" size="40" readonly>
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
答案 0 :(得分:0)
将其更改为:
<input name="Admin_no" type= "text" disabled="disabled" value=<?php echo $_SESSION['txtName'] ?>"
答案 1 :(得分:0)
您的$_SESSION
值存储在服务器上的文本文件中,每次使用会话时都会加载。
$_SESSION
构造可以像数组一样使用。
// store in session
$_SESSION['adminId'] = 1;
// load from session
$variable = $_SESSION['adminId'];
// delete a session variable
unset($_SESSION['adminId']);
// delete a session
session_destroy();
// php echo short code
<input value="<?=$variable?>" type="text" />