我有以下表格。问题是当用户单击提交按钮时,页面将刷新。如果他们再次点击提交按钮,则会创建帐户。
我希望他们只需要点击一次提交按钮即可创建用户帐户。
<?php
if(!defined('__CONFIG__'))
{
header("location:../index.php");
die();
}
if(!empty($_SESSION['member_id'])){
header("location: ".URLS.url_formating("my-account"));
exit();
}
include_once(APATH."includes/left.php");
$msg = "";
if(!empty($_POST['registration_sbmt'])){
$msg = "";
$username = inputEscapeString(loadVariable('email',''));
$ref = inputEscapeString(loadVariable('ref',''));
$fname = inputEscapeString(loadVariable('fname',''));
$lname = inputEscapeString(loadVariable('lname',''));
$email = inputEscapeString(loadVariable('email',''));
$company_name = inputEscapeString(loadVariable('company_name',''));
$phone = inputEscapeString(loadVariable('phone',''));
$bstreet = inputEscapeString(loadVariable('bstreet',''));
$baddress = inputEscapeString(loadVariable('baddress',''));
$bcity = inputEscapeString(loadVariable('bcity',''));
$bzip = inputEscapeString(loadVariable('bzip',''));
$bcountry = inputEscapeString(loadVariable('bcountry',''));
$bstate = inputEscapeString(loadVariable('bstate',''));
$zip = inputEscapeString(loadVariable('zip',''));
$sname = inputEscapeString(loadVariable('sname',''));
$sstreet = inputEscapeString(loadVariable('sstreet',''));
$saddress = inputEscapeString(loadVariable('saddress',''));
$scity = inputEscapeString(loadVariable('scity',''));
$szip = inputEscapeString(loadVariable('szip',''));
$scountry = inputEscapeString(loadVariable('scountry',''));
$sstate = inputEscapeString(loadVariable('sstate',''));
$password = inputEscapeString(loadVariable('pwd',''));
$password_1 = inputEscapeString(loadVariable('pwdc',''));
$member_type = inputEscapeString(loadVariable('member_type',''));
if($is_newsletter != 1)$is_newsletter = 0;
$error_count = array();
$username_error = false;
if(empty($username) && trim($username)==""){
$username_error = true;
$error_count[]= "Enter username.<br />";
}
if(empty($_POST['fname']) && trim($_POST['fname'])==""){
$error_count[]= "Enter first name.<br>";
}
if(empty($_POST['lname']) && trim($_POST['lname'])==""){
$error_count[]= "Enter last name.<br>";
}
$email_error = false;
if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._- ]+)+$/", $email)){
$email_error = true;
$error_count[]= "Enter valid email-id.<br>";
}
if(empty($bcity) && trim($bcity)==""){
$error_count[]= "Enter city<br>";
}
if($bcountry=='1' || $bcountry=='2')
{
if(empty($bstate) && trim($bstate)==""){
$error_count[]= "Select your state/province.<br>";
}
}
if(empty($bcountry) && trim($bcountry)==""){
$error_count[]="Select country<br>";
}
if(empty($bzip) && trim($bzip)==""){
$error_count[]= "Enter zip<br>";
}
if(empty($phone) && trim($phone)==""){
$error_count[]="Enter Home or Business or Cell phone number<br>";
}
if(empty($password) && trim($password)==""){
$error_count[]= "Enter password";
}
if(empty($password_1) && trim($password_1)==""){
$error_count[]= "Enter confirm password";
}
elseif($password != $password_1){
$error_count[]= "Enter same confirm password";
}
if($username_error == false){
$sql = "SELECT * FROM `members` WHERE `username`='".$username."'";
$objDB->setQuery($sql);
$rs_login = $objDB->select();
if(count($rs_login)>0){
$error_count[]= "Username already exists.<br>";
}
}
if($email_error == false){
$sql = "SELECT * FROM `members` WHERE `email`='".$email."'";
$objDB->setQuery($sql);
$rs_login = $objDB->select();
if(count($rs_login)>0){
$error_count[]= "Email ID already exists.<br>";
}
}
if($email_error == false){
$sql = "SELECT * FROM `banned_subscribers` WHERE `ban_value`='".$email."'";
$objDB->setQuery($sql);
$rs_login = $objDB->select();
if(count($rs_login)>0){
$error_count[]= "This email address is banned ,you can't register. <br>";
}
}
if($email_error == false){
$sql = "SELECT * FROM `banned_subscribers` WHERE `ban_value`='".$_SERVER['REMOTE_ADDR']."'";
$objDB->setQuery($sql);
$rs_login = $objDB->select();
if(count($rs_login)>0){
$error_count[]= "Sorry your ip address is blocked,you can't register.<br>";
}
}
if($email_error == false){
$ar=@split("@",$email);
$sql = "SELECT * FROM `banned_subscribers` WHERE `ban_value`='".$ar[1]."'";
$objDB->setQuery($sql);
$rs_login = $objDB->select();
if(count($rs_login)>0){
$error_count[]= "Sorry from this email domain,you can't register. <br>";
}
}
if(empty($_SESSION['captcha_2webdesign']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha_2webdesign'])
{
$error_count[]= "Please enter the valid security code.<br>";
unset($_SESSION['captcha_2webdesign']);
}
if(empty($error_count)){
unset($_SESSION['captcha_2webdesign']);
$sql = "insert into members set username = '".$username."', email = '".$email."',
password = '".md5($password)."',pwd_hint = '".$password."', reg_date = '".date("Y-m-d")."',
is_active = '1',`last_login`=NOW() ,`login_times`=(`login_times`+1)";
$objDB->setQuery($sql);
$rs_registration = $objDB->insert();
$sql = "SELECT * FROM `members` WHERE `username`='".$username."' AND `password`='".md5($password)."'";
$objDB->setQuery($sql);
$rs_registration = $objDB->select();
$member_id = $rs_registration[0]['member_id'];
$sql = "insert into member_details set member_id ='".$member_id."',
fname ='".$fname."',
lname ='".$lname."',
company_name ='".$company_name."',
phone = '".$phone."',
bstreet = '".$bstreet."',
baddress ='".$baddress."',
bcity ='".$bcity."', bzip ='".$bzip."',
bcountry ='".$bcountry."',
bstate ='".$bstate."',
sname ='".$sname."',
sstreet ='".$sstreet."',
saddress ='".$saddress."',
scity ='".$scity."',
szip='".$szip."'
,scountry = '".$scountry."'
,sstate='".$sstate."'
,member_type='".$member_type."'
";
$objDB->setQuery($sql);
$rs_registration = $objDB->insert();
}
}
?>
<link rel="stylesheet" href="<?php echo URL;?>validator/css/validationEngine.jquery.css" type="text/css"/>
<script src="<?php echo URL;?>validator/js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="<?php echo URL;?>validator/js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
// binds form submission and fields to the validation engine
jQuery("#member_registration").validationEngine();
});
</script>
<div class="rightpanel">
<form action="" method="post" name="member_registration" id="member_registration" autocomplete="off">
<div class="">
<input type="reset" class="cancel" value="" />
<input type="submit" class="save" value="" />
<input type="hidden" name="registration_sbmt" value="1" />
</div>
</form>
</div>
<div style="clear:both"></div>
<link rel="stylesheet" type="text/css" href="<?php echo URL;?>css/dd.css" />
<script type="text/javascript" src="<?php echo URL;?>js/jquery.dd.js"></script>
<!--ddcss ends-->
<script type="text/javascript">
function showval(value){
if( value == true ){
var full_name =$("#fname").val()+" "+$("#lname").val();
$("#sname").val(full_name);
$("#sstreet").val($("#bstreet").val());
$("#saddress").val($("#baddress").val());
$("#scity").val($("#bcity").val());
$("#szip").val($("#bzip").val());
$("#scountry").val($("#bcountry").val());
$("#sstate").val($("#bstate").val());
}
else{
$("#sname").val('');
$("#sstreet").val('');
$("#saddress").val('');
$("#scity").val('');
$("#szip").val('');
$("#scountry").val('');
$("#sstate").val('');
}
}
</script>
当我点击提交按钮时,它会影响数据库,并且用户获得创建它的jts,它不会将其重定向到我的帐户页面。但是当用户第二次点击时,用户被重定向到我的帐户页面,这次数据库不受影响。
我认为问题在于此代码段。
if(!empty($_SESSION['member_id'])){
header("location: ".URLS.url_formating("my-account"));
exit();
}
这可能对某人有帮助