我正在使用 twitter 引导模式窗口进行注册表单。当我在填写表格后点击“注册”时,它会将数据发送到 mysql 并开始会话。
如何确保一个人留在他点击“注册”链接的同一网页上。
<!DOCTYPE html>
<html>
<head>
<link href="http://www.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://www.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$("#ajax-contact-form").submit(function(){
var str = $(this).serialize();
$.ajax(
{
type: "POST",
url:"register_process.php",
data: str,
success:function(result)
{
$("#div1").html(result);
}
});
return false;
});
});
</script>
</head>
<body>
<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">SIGN UP</a>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<div id="contact_form">
<form id="ajax-contact-form" name="contact" action="">
<fieldset>
<div class="field_container">First Name:</label>
<input type="text" name="cust_firstname" id="firstname" maxlength="50" style="width: 250px; height: 30px"; />
<div class="field_container">Last Name:</label>
<input type="text" name="cust_lastname" id="lastname" maxlength="50" style="width: 250px; height: 30px"; />
<div class="sex_check" >
<input type="radio" name="cust_sex" type="radio" value="M" /> Male
<input type="radio" name="cust_sex" type="radio" value="F" /> Female
<hr class="line_break">
<div class="field_container">Email:</label>
<input type="text" name="cust_email" id="email" maxlength="100" style="width: 250px; height: 30px"; />
<div class="field_container">Password:</label>
<input type='password' name='cust_password' id='password' maxlength="12" style="width: 250px; height: 30px"; />
<div class="field_container">Confirm Password:</label>
<input type='password' name='cust_password2' id='confirmpassword' maxlength="12" style="width: 250px; height: 30px"; />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<INPUT class="btn btn-primary" type="submit" name="submit" value="Register" >
</fieldset>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
<div id="div1">
</div>
</body>
</html>
register_process.php 如下
<?php
ob_start();
session_start();
require_once("config.php");
require_once("all_functions.php");
$cust_firstname = stripslashes($_POST['cust_firstname']);
$cust_lastname = stripslashes($_POST['cust_lastname']);
$cust_sex = stripslashes($_POST['cust_sex']);
$cust_email = stripslashes($_POST['cust_email']);
$cust_password = stripslashes($_POST['cust_password']);
$cust_password2 = stripslashes($_POST['cust_password2']);
$res = mysql_query("SELECT * FROM register WHERE cust_email = '$cust_email'");
if (mysql_num_rows($res)>0)
{
echo 'That email is already registered';
exit;
}
mysql_query("INSERT INTO register (`cust_firstname`,`cust_lastname`, `cust_sex`, `cust_email`, `cust_password`)
VALUES
('$cust_firstname', '$cust_lastname', '$cust_sex', '$cust_email', '$cust_password')");
$_SESSION['valid_user'] = $cust_email;
header("Location: http://tripneat.com/");
exit;
?>