你能帮我么。我是 PHP 的初学者,仍在学习该语言的基础知识。我目前正在学习如何创建会话。当我尝试书中的一个例子时,显然有一个错误。HTML 表单如下所示:
<form action="session_registration_form_script.php" method="post">
<label for="name">Name:</label>
<input type="text" name="name" />
<label for="email">Email:</label>
<input type="text" name="email" />
<input type="submit" value="Register" />
</form>
PHP脚本类似于:
<?php
// Initialize session data
session_start();
/*
* If the user is already registered, display a
* message letting them know.
*/
if(isset($_SERVER['username'])) {
echo "You're already registered as $_SESSION[username]";
}
// Checks if the form was submitted
else if($_SERVER['REQUEST_METHOD'] == 'POST') {
/*
* If both the username and email fields were filled
* out, save the username in a session variable and
* output a thank you message to the browser. To
* eliminate leading and trailing whitespace, we use the
* trim() function
*/
if(!empty(trim($_POST['username']))
&& !empty(trim($_POST['email']))) {
// Store escaped $_POST values in variables
$uname = htmlentities($_POST['username']);
$email = htmlentities($_POST['email']);
$_SESSION['username'] = $uname;
echo "Thanks for registering! <br />",
"Username: $uname <br />",
"Email: $email <br />";
}
/*
* If the user did not fill out both fields, display
* a message letting them know that both fields are
* required for registration
*/
else {
echo "Please fill out both fields! <br />";
}
}
// If the form was not submitted, dispalys the HTML form
else {
?>
<?php } ?>
当我在浏览器上输出这两个文件时,浏览器报告:致命错误:无法在“文件路径”和代码行的写入上下文中使用函数值。
请通过修复此问题提供帮助,并随时添加您可能认为对我有用的任何内容。提前致谢...