从jquery post表单超出了最大调用堆栈大小

时间:2017-06-15 12:54:06

标签: php jquery html post

我正在构建用户管理系统的过程中,但是我的注册表遇到了问题,并且不断收到以下错误:

  

未捕获RangeError:超出最大调用堆栈大小

这是我目前正在使用的表单html和jquery:

$(document).ready(function(){

$("#login").click(function(){
var process = "login";
var email = $("#loginemail").val();
var password = $("#loginpassword").val();
if($('#remember').is(':checked')) {
var remember = '1';
}
	
$.post("process.php", {process: process,email: email,password: password,remember: remember}, function(result){
    
	if(result === 'Login Successful!'){
		document.location.href = 'index.php';
	}
	else{
	$("#response").html(result);
	$("#response").show();
	}
});
return false;
});

$("#register").click(function(){
var process = "register";
var username = $("#regusername").val();
var email = $("#regemail").val();
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
var password = $("#regpassword").val();
var conpassword = $("#conregpassword").val();
$.post("process.php",{process:process,username:username,email:email,firstname:firstname,lastname:lastname,password:password,conpassword:conpassword}, function(result){
    $("#response").html(result);
	$("#response").show();
});
return false;
});

$("#registerlink").click(function(){
$("#response").hide();
$(".loginform").slideToggle( "slow" );
$(".registerform").slideToggle( "slow" );
return false;
});

$("#loginlink").click(function(){
$("#response").hide();
$(".registerform").slideToggle( "slow" );
$(".loginform").slideToggle( "slow" );
return false;
});

});
<form class="registerform" method="post" action="#">
<h2>Register</h2>
<label>Username :</label>
<input type="text" name="regusername" id="regusername" placeholder="Username" required>
<label>Email :</label>
<input type="text" name="regemail" id="regemail" placeholder="Email" required>
<label>Real Name :</label>
<input type="text" name="firstname" id="firstname" placeholder="First" required>
<input type="text" name="lastname" id="lastname" placeholder="Last" required>
<label>Password :</label>
<input type="password" name="regpassword" id="regpassword" placeholder="Password" required>
<label>Confirm Password :</label>
<input type="password" name="conregpassword" id="conregpassword" placeholder="Confirm Password" required>
<input type="button" name="register" id="register" value="Register">
<span>Already have an account? <a href="#" id="loginlink">Login here!</a></span>
</form>

function register($username,$email,$first,$last,$password,$conpassword){
global $con;

if(isset($username)){
    if(strlen($username < 5)){
        echo 'Username must be at least 5 characters long!';
        exit;
    }
    if(!preg_match('/^\w{5,}$/', $username)) { // \w equals "[0-9A-Za-z_]"
         echo 'Invalid Username!';
        exit;
    }
    $sql = "SELECT * FROM users WHERE username = '".$username."'";
    $query = $con->query($sql);
    if ($query->num_rows > 0) {
    echo 'Username already in use!';
    exit;
    }
}

if(isset($email)){
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
           echo("$email is an invalid email address");
        exit;
     }
$sql = "SELECT * FROM users WHERE email = '".$email."'";
$query = $con->query($sql);
    if ($query->num_rows > 0) {
    echo 'Email Address already in use!';
    exit;
    }
}
if($password != $conpassword){
    echo 'Passwords dont match!';
    exit;
}

$password = md5($password);
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
    for ($i = 0; $i < 20; $i++) {
         $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
$secureString = md5($randomString);

$sql = "INSERT INTO users (username, email, password, verified, verify_code, first, last) VALUES ('".$username."', '".$email."', '".$password."', '0', '".$secureString."', '".$first."', '".$last."')";
$query = $con->query($sql);

if($query){
    //send email
    $to = $email;
    $subject = 'Email Verification';
    $from = 'admin@curious-coders.com';

    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Create email headers
    $headers .= 'From: '.$from."\r\n".
    'Reply-To: '.$from."\r\n" .
    'X-Mailer: PHP/' . phpversion();

    // Compose a simple HTML email message
    $message = '<html><body>';
    $message .= '<h1>Hi '.$username.'!</h1>';
    $message .= '<p>Thank you for registering with us!</p>';
    $message .= '<p>In order to verify your email address and activate your account, please <a href="http://development.curious-coders.com/login/verify.php?token='.$secureString.'">click here</a></p>';
    $message .= '</body></html>';

    // Sending email
    if(mail($to, $subject, $message, $headers)){
         echo 'A verification email has been sent to '.$to.'!';
        exit;
    }
    else{
         echo 'Unable to send verification email. Please try again.';
        exit;
    }
}

}

我已经四处搜索,并且听到很多关于重复出现的函数创建无限循环但我似乎无法在我的代码中发现它,我必须忽略一些东西。 任何帮助将不胜感激。

0 个答案:

没有答案