我正在尝试制作一个注册表单,基本上我有 4 页,第一页要求输入名字、姓氏和电子邮件,第二页要求输入出生日期和密码,第 3 页将询问一些统计信息/复选框项目和第 4 页将提交表格。
目前,我正在尝试将数据从一页上的一个表单回显到第 2、3 页,然后最后在第 4 页一起提交到 mysql 数据库中。
我收到更新数据库消息的错误。
有人可以告诉我我做得对还是有更简单的方法?
谢谢;
<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 页
<? ob_start(); ?>
<?php
// GET ACCOUNT INFORMATION FROM FORM AND ASSIGN VARIABLES
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
?>
<?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 />";
*/
?>
<?php
////// SEND TO DATABASE
/////////////////////////////////////////////////////////
// Database Constants
define("DB_SERVER", "#######");
define("DB_USER", "######");
define("DB_PASS", "");
define("DB_NAME", "######");
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
// 2. Select a database to use
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
//////////////////////////////////////////////////////////////
$query="INSERT INTO registrations (Id,
first_name,
last_name,
email
)
VALUES('NULL',
'".$first_name."',
'".$last_name."',
'".$email."'
)";
mysql_query($query) or die ('Error updating database');
?>
<?php
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}
function get_user_id() {
global $connection;
global $email;
$query = "SELECT *
FROM registrations
WHERE email = \"$email\"
";
$user_id_set = mysql_query($query, $connection);
confirm_query($user_id_set);
return $user_id_set;
}
?>
<?php
$user_id_set = get_user_id();
while ($user_id = mysql_fetch_array($user_id_set)) {
$cookie1 = "{$user_id["id"]}";
setcookie("registrations", $cookie1, time()+3600); /* expire in 1 hour */
}
?>
<? ob_flush(); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Register</title>
<!-- The stylesheet -->
<link rel="stylesheet" href="assets/css/styles.css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div id="main">
<h2>Step 2: Security Details</h2>
<br/>
<form class="" method="post" action="register_p3.php">
<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 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>
</div>
<!-- JavaScript includes - jQuery, the complexify plugin and our own script.js -->
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="assets/js/jquery.complexify.js"></script>
<script src="assets/js/script.js"></script>
</body>
</html>