我真的无法弄清楚为什么这不起作用。我想将存储在php会话变量中的内容显示为输入字段中的值。
<?php
if($_SESSION['id'])
echo ' <input type="text" value="'.$_SESSION['friday'].'"></input>'; ?>
提前致谢!
更新: 在我的登录页面index.php,我开始会话并为它们分配值。
$row = mysql_fetch_assoc(mysql_query("
SELECT *
FROM knine_settings_login, knine_school_db, knine_class_db
WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."' AND knine_settings_login.School = knine_school_db.School AND knine_settings_login.ClassID = knine_class_db.ClassID AND knine_class_db.week = 0
"));
if($row['usr'])
{
// If everything is OK login
$_SESSION['usr']=$row['usr'];
$_SESSION['id'] = $row['id'];
$_SESSION['homework'] = $row['homework'];
$_SESSION['pe'] = $row['pe'];
$_SESSION['pm'] = $row['pm'];
$_SESSION['pc'] = $row['pc'];
$_SESSION['School'] = $row['School'];
$_SESSION['Class'] = $row['Class'];
$_SESSION['level'] = $row['level'];
$_SESSION['rememberMe'] = $_POST['rememberMe'];
$_SESSION['schoolurl'] = $row['schoolurl'];
$_SESSION['monday']=$row['monday'];
$_SESSION['tuesday'] = $row['tuesday'];
$_SESSION['wednesday'] = $row['wednesday'];
$_SESSION['thursday'] = $row['thursday'];
$_SESSION['friday'] = $row['friday'];
$_SESSION['peone'] = $row['peone'];
$_SESSION['petwo'] = $row['petwo'];
答案 0 :(得分:1)
Session
在使用之前需要先启动它。试试吧。
<?php
session_start();
if(isset($_SESSION['id']))
echo '<input type="text" value="'.$_SESSION['friday'].'"></input>';
?>
答案 1 :(得分:0)
确保在回显任何session_start()
数据之前调用了$_SESSION
。
<?php
session_start();
if ($_SESSION['id']) {
echo ' <input type="text" value="'.$_SESSION['friday'].'"></input>';
}
?>
答案 2 :(得分:0)
<?php
// Start the session on every page at the top first
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["animals"] = "dog";
$_SESSION["cars"] = "ford";
echo ' <input type="text" value="'.$_SESSION['animals'].'"></input>';
?>