我正在尝试将变量从(register.php)传递到(submit.php),最后传递给(yes.php) - 请注意我已经包含了' session_start();'在每个页面中作为'包含'在主要的php页面上。
register.php - 1
<div id = "content">
<form action="submit.php" method="post">
<ul>
<li>
Username*:<br>
<input type="text" name="username">
</li>
<br>
<li>
Email Address*:<br>
<input type="text" name="email">
</li>
<br>
<li>
Telephone Number*:<br>
<input type="text" name="telephone">
</li>
<br>
<li>
Telephone Again*: <br>
<input type="text" name="telephoneagain">
<br>
</li>
<li>
<input type="submit" name="submit">
</li>
</ul>
</form>
</header>
这是一个非常基本的注册表格。 然后它被发送到
submit.php - 2
<?php
<div id = "content">
<div id = "feature">
Your username is: <?php echo $_POST['username']; ?> <br>
Your email address is: <?php echo $_POST['email']; ?> <br>
Your telephone number is: <?php echo $_POST['telephone']; ?> <br>
Just to confirm your telephone number: <?php echo $_POST['telephoneagain']; ?>
<br>
<br>
</div>
<div id = "validation">
Is this correct? <br>
<li> <a href="yes.php"> Yes </a> </li>
<li> <a href="register.php"> No </a> </li>
<?php
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['telephone'] = $telephone;
$_SESSION['telephoneagain'] = $telephoneagain;
?>
</div>
</header>
再次相当基本,忽略缺乏验证。所以在这里,我可以回复一下在register.php上输入的用户名。然后我点击“是”&#39;表明信息是正确的。
yes.php - 3
<?php
$_POST['username'];
?>
<?php
if(isset($_SESSION['username']))
echo $_SESSION['username'];
?>
<?php
$sql = "INSERT INTO users (username, email, telephone, telephoneagain)
VALUES ('$username', '$email', '$telephone', '$telephoneagain')";
?>
这里的问题是变量没有从上一页传递,因此页面找不到它们。
人们问我最后一页是否有session_start(),这里是完整代码
这是针对yes.php - 3
<?php
include 'includes/yes/yeshead.php';
include 'includes/yes/yesheader.php';
include 'includes/yes/yescontent.php';
include 'includes/yes/yesnav.php';
include 'includes/yes/yesfooter.php';
include 'core/init.php'; ?>
init.php包含session_start();
<?php
session_start();
error_reporting(-1);
require 'core/database/connect.php';
require 'core/users.php';
$current_file = explode('/', $_SERVER['SCRIPT_NAME']);
$current_file = end($current_file);
$errors = array();
?>
答案 0 :(得分:1)
非常善良的Alex帮助我解决了这个问题。我会给他答案,但他发表了评论,所以这就足够了
答案 1 :(得分:0)
Helo,试试submit.php:
$_SESSION['username'] = $_POST['username'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['telephone'] = $_POST['telephone'];
$_SESSION['telephoneagain'] =$_POST['telephoneagain'];
并在yes.php中:
$username = $_POST['username'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$telephoneagain =$_POST['telephoneagain'];
答案 2 :(得分:0)
在与会话相关的代码之前,请使用session_start();
。
您包含与会话相关的文件,之后您包含一个包含session_start();
的文件。首先包含session_start();
包含的文件。
所以在yes.php中使用它:
<?php
include 'core/init.php';
include 'includes/yes/yeshead.php';
include 'includes/yes/yesheader.php';
include 'includes/yes/yescontent.php';
include 'includes/yes/yesnav.php';
include 'includes/yes/yesfooter.php';
?>
因此,请确保在每个使用会话的代码中添加session_start();
,否则它将无效。