我正在尝试携带或回显用户在表单中输入的信息,用户需要完成 3 个表单,它们都在不同的页面上,当他们到达第 4 页时,我需要插入所有这些信息一起进入mysql数据库。
现在我有我的 sql 查询,它将数据放入数据库,这输入数据很好,但只将数据放入最后一页/这是用户完成的最后一个表单。即使我正在使用这些值,用户放入早期表单的任何其他先前信息都不会输入到 mysql 中。
我认为您需要创建一个会话将数据传送到下一页,所以我正在尝试这样做,但它不起作用:
第 1 页/表格 1:
<?php
session_start();
?>
<form class="" method="post" action="register_p2.php">
<div class="row first_name">
<input type="text" id="first_name" name="first_name" placeholder="First Name" />
</div>
<div class="row last_name">
<input type="text" id="last_name" name="last_name" placeholder="Last Name" />
</div>
<div class="row email">
<input type="email" id="email" name="email" placeholder="Email" />
</div>
<input type="submit" value="Next >" />
</form>
第 2 页/表格 2:
<?php
session_start();
// other php code here
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;
?>
<form name="myForm" method="post" action="register_p3.php" onsubmit="return validateForm()" >
<div class="row date_of_birth">
<input type="text" id="date_of_birth" name="date_of_birth" placeholder="D.O.B 10/02/1990" />
</div>
<div class="row number">
<input type="text" id="contact_number" name="contact_number" placeholder="Mobile Number" />
</div>
<div class="row confirm">
<input type="text" id="confirm" name="confirm" placeholder="Are You a UK resident?" />
</div>
<input type="submit" value="Next >" />
</form>
第 3 页/表格 3:
<?php
session_start();
// other php code here
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;
$_SESSION['dat_of_birth'] = $date_of_birth;
$_SESSION['number'] = $number;
?>
<form class="" method="post" action="register_p4.php">
<div class="row date_of_birth">
<input type="text" id="display_name" name="display_name" placeholder="Display Name" />
</div>
<div class="row password">
<input type="password" id="password" name="password" placeholder="Password" />
</div>
<div class="row password2">
<input type="password" id="password2" name="password2" placeholder="Password (Confirm)" />
</div>
<input type="submit" value="Next >" />
</form>
然后在最后一页上,我尝试像这样收集所有信息并将其输入数据库:
<? ob_start(); ?>
<?php
// GET ACCOUNT INFORMATION FROM FORM AND ASSIGN VARIABLES
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$date_of_birth = $_POST['date_of_birth'];
$contact_number = $_POST['contact_number'];
$display_name = $_POST['display_name'];
$password = $_POST['password'];
?>
<?php
/*
// ECHO ACCOUNT INFORMATION
echo "<strong> Account Information: </strong>";
echo "<br />";
echo First Name: ";
echo "<br />";
echo $first_name;
echo "<br />";
echo "<br />";
echo "Last Name: ";
echo "<br />";
echo $last_name;
echo "<br />";
echo "<br />";
echo "Email: ";
echo "<br />";
echo $email;
echo "<br />";
echo "<br />";
echo "Password: ";
echo "<br />";
echo $password;
echo "<br />";
echo "<br />";
echo "date_of_birth: ";
echo "<br />";
echo $date_of_birth;
echo "<br />";
echo "<br />";
echo "Contact_number: ";
echo "<br />";
echo $contact_number;
echo "<br />";
echo "<br />";
echo "display_name: ";
echo "<br />";
echo $display_name;
echo "<br />";
echo "<br />";
*/
?>