为了说明问题,我是一名研究Web开发的大学生。所以我的任务是创建一个表单,要求用户提供信息,基本上只需使用PHP
传递数据并确定数据是否实际填写完毕。长话短说,我已经决定将我的数据存储在SESSION
只是为了给自己更多的练习,但每当我尝试回显一个SESSION
变量时,我得到一个未定义的变量通知。我已经研究了几个小时,似乎无法找到问题。我真正找到的就是确保SESSION
大写,start_session()
位于每个文档的顶部。请帮忙!
的index.php
<?php require('functions.php'); ?>
<!DOCTYPE html>
<html>
<head>
<title>Form Assignment</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="form">
<form action="form-submit.php" method="POST">
<label for="name">Name:</label><br>
<input name="name" type="text" ><br>
<label for="email">Email:</label><br>
<input name="email" type="email"><br>
<label for="phone">Phone #:</label><br>
<input name="phone" type="tel"><br>
<label for="address">Address:</label><br>
<input name="address" type="text"><br>
<label for="city">City:</label><br>
<input name="city" type="text"><br>
<label for="state">State:</label><br>
<select name="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
<br>
<label for="zipcode">Zip Code:</label><br>
<input name="zipcode" type="text"><br>
<label for="message">Message:</label><br>
<textarea name="message" cols="30" rows="5"></textarea>
<br>
<input type="submit" name="submit" value="submit">
</form>
</div>
</body>
</html>
形状submit.php
<?php require('functions.php');
if (isset($_POST['submit'])) {
$_SESSION['name'] = $_POST['name'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['phone'] = $_POST['phone'];
$_SESSION['address'] = $_POST['address'];
$_SESSION['city'] = $_POST['city'];
$_SESSION['state'] = $_POST['state'];
$_SESSION['zipcode'] = $_POST['zipcode'];
$_SESSION['message'] = $_POST['message'];
echo $SESSION["email"];
}
else { //Redirects user to form
header('Location: index.php');
exit;
}
?>
的functions.php
<?php
session_start();
//Check for an active session
if (isset($_COOKIE['PHPSESSID'])) {
// $_SESSION['user'] = null;
}
else {
//Do nothing
}
?>
答案 0 :(得分:2)
你在回声中忘记了_。
$_SESSION["email"];