PHP/Ajax没有返回正确的错误并且没有识别POST变量?

PHP/Ajax没有返回正确的错误并且没有识别POST变量?,php,javascript,jquery,html,ajax,Php,Javascript,Jquery,Html,Ajax,每次它都回来哎呀必须输入所有输入。仔细检查表格 它应该返回行中的下一个错误,但我猜它没有识别我的POST变量?为什么会这样 代码如下: PHP脚本: if(isset($_POST['action'])) { switch($_POST['action']) { case 'register': $email_adress = @$_POST['register_email_address']; $password = hash('sh

每次它都回来哎呀必须输入所有输入。仔细检查表格

它应该返回行中的下一个错误,但我猜它没有识别我的POST变量?为什么会这样

代码如下:

PHP脚本:

if(isset($_POST['action'])) {
    switch($_POST['action']) {

        case 'register':

        $email_adress = @$_POST['register_email_address'];
        $password = hash('sha512', @$_POST['register_password']);
        $confirm_password = hash('sha512', @$_POST['register_confirm_password']);
        $safe_pin = @$_POST['register_safe_pin'];

            if(isset($email_address, $password, $confirm_password, $safe_pin)) {

                if(filter_var($email_address, FILTER_VALIDATE_EMAIL)) {

                    if($password == $confirm_password) {

                        if(strlen($safe_pin) == 4 && is_numeric($safe_pin)) {

                            if(strlen($_POST['register_password']) >= 6 && strlen($_POST['register_confirm_password']) >= 6) {

                                $insert_user = $db->prepare("INSERT INTO `users`
                                (`email_address`, `password`, `safe_pin`, `time_registered`, `activated`, `balance`, `last_login, `ip_address`, `last_ip_address`)
                                VALUES (:email_address, :password, :safe_pin, :time_registered, :activated, :balance, :last_login, :ip_address, :last_ip_address)");

                                    $insert_user->execute(array(

                                        ':email_address'        => $email_address,
                                        ':password'             => $password,
                                        ':safe_pin'             => $safe_pin,
                                        ':time_registered'      => time(),
                                        ':activated'            => 0,
                                        ':balance'              => 0,
                                        ':last_login'           => 0,
                                        ':ip_address'           => $_SERVER['REMOTE_ADDR'],
                                        ':last_ip_address'      => $_SERVER['REMOTE_ADDR']

                                    ));

                            }

                            else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your password must be a minimum of 6-characters.')); }
                        }
                            else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your safe-pin must be a 4-character numeric code.')); }
                    }
                            else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your confirmation password must match identically to your password.')); }
                }
                            else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your e-mail address must be valid.  Make sure it\'s typed properly. <br />')); }
            }
                            else { echo json_encode(array('result'  => '<strong>Oops!</strong> All inputs must be entered.  Double-check the form. <br />')); }

        break;
   }
}
if(isset($\u POST['action'])){
开关($\u POST['action'])){
“登记册”一案:
$email_address=@$_POST['register_email_address'];
$password=hash('sha512',@$_POST['register_password']);
$confirm_password=hash('sha512',@$_POST['register_confirm_password']);
$safe_pin=@$_POST['register_safe_pin'];
如果(设置($email\u address、$password、$confirm\u password、$safe\u pin)){
if(过滤变量($email\u地址,过滤验证\u email)){
如果($password==$confirm\u password){
if(strlen($safe\u pin)==4&&is\u numeric($safe\u pin)){
如果(strlen($\u POST['register\u password'])>=6和&strlen($\u POST['register\u confirm\u password'])>=6){
$insert_user=$db->prepare(“插入到`users中`
(`email\u address`、`password`、`safe\u pin`、`time\u registed`、`activated`、`balance`、`last\u login`、`ip\u address`、`last\u ip\u address`)
值(:email\u address、:password、:safe\u pin、:time\u registed、:activated、:balance、:last\u login、:ip\u address、:last\u ip\u address));
$insert_user->执行(数组)(
':email_address'=>$email_address,
':password'=>$password,
“:safe_pin”=>$safe_pin,
':time_registed'=>time(),
“:已激活”=>0,
“:余额”=>0,
':上次登录'=>0,
“:ip地址”=>$\u服务器[“远程地址”],
':last_ip_address'=>$\u服务器['REMOTE\u ADDR']
));
}
否则{echo json_encode(数组('result'=>'Oops!您的密码必须至少为6个字符)。);}
}
否则{echo json_encode(数组('result'=>'Oops!您的安全pin必须是4个字符的数字代码)。);}
}
否则{echo json_encode(数组('result'=>'Oops!您的确认密码必须与您的密码完全匹配。);}
}
否则{echo json_encode(数组('result'=>'Oops!您的电子邮件地址必须有效。请确保键入正确。
');} } 否则{echo json_encode(数组('result'=>'Oops!必须输入所有输入。请仔细检查表单。
');} 打破 } }
jQuery/Javascript

<script type="text/javascript">
  $("#sign_up").on('click', function() {
    $.post('./includes/ajax.php', { action: 'register' } , function(result) {
      var result = JSON.parse(result);
        console.log(result.result);
        $("#register_result").append(result.result);
    });
  });
$("#register_form").submit(function() {
  return false;
});

$(".alert").hide();
$("#sign_up").on('click', function() { $(".alert").show(); });
</script>

$(“#注册”)。在('单击',函数()上{
$.post('./包括/ajax.php',{action:'register'},函数(结果){
var result=JSON.parse(result);
console.log(result.result);
$(“#register_result”).append(result.result);
});
});
$(“#登记表”)。提交(函数(){
返回false;
});
$(“.alert”).hide();
$(“#注册”).on('click',function(){$(“.alert”).show();});
HTML代码:

<div id="register_form">
              <form class="bs-example form-horizontal" id="register_form" method="POST" action="./includes/ajax.php">
                <fieldset>
                  <legend>Create a Wallet</legend>
                      <div class="alert alert-dismissable alert-danger">
              <button type="button" class="close" data-dismiss="alert">&times;</button>
             <span id="register_result"></span>
            </div>
                  <div class="form-group">
                    <label for="inputEmail" class="col-lg-2 control-label">Email</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" id="inputEmail" placeholder="Your E-mail Address." name="register_email_address">
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="inputPassword" class="col-lg-2 control-label">Password</label>
                    <div class="col-lg-10">
                      <input type="password" class="form-control" id="inputPassword" placeholder="Your 6-character password." name="register_password">
                    </div>
                  </div>
                      <div class="form-group">
                    <label for="inputPassword" class="col-lg-2 control-label">Confirm</label>
                    <div class="col-lg-10">
                      <input type="password" class="form-control" id="inputPassword" placeholder="Your 6-character password." name="register_confirm_password">
                    </div>
                  </div>
                        <div class="form-group">
                    <label for="inputPassword" class="col-lg-2 control-label">Safe-Pin</label>
                    <div class="col-lg-10">
                      <input type="password" class="form-control" id="inputPassword" placeholder="Your 4-digit safe-pin." name="register_safe_pin">
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="col-lg-10 col-lg-offset-2">
                      <button type="submit" class="btn btn-primary" id="sign_up">Sign Up</button> 
                    </div>
                  </div>
                </fieldset>
              </form>
            </div>

创建一个钱包
&时代;
电子邮件
密码
证实
保险别针
注册

我现在更新了我的全部答案。。。因为您的代码中有不止一个错误

首先,你要做的是,买一个IDE(软件)来突出显示错误。这可以让你的生活变得如此轻松

尽可能经常地展示你的代码,上下阅读,一遍又一遍,注释出一些代码行来测试错误。。。等等

我认为这段代码现在是绝对没有错误和清晰的

我改变的是:

  • $email\u address
    $email\u address

  • if(strlen($\u POST['register\u password'])>=6和&strlen($\u POST['register\u confirm\u password'])>=6){…

    if(strlen($\u POST['register\u password'])>5和&strlen($\u POST['register\u confirm\u password'])>5){…

  • :password
    :pwd
    我更改了,因为这可能是一个保留字,而且不太明显(可以随意更改)

  • (忘记倒勾)

    而整个代码:

    if (isset($_POST['action'])) {
    
        switch($_POST['action']) {
    
        case 'register':
    
            $email_address      = @$_POST['register_email_address'];
            $password           = hash('sha512', @$_POST['register_password']);
            $confirm_password   = hash('sha512', @$_POST['register_confirm_password']);
            $safe_pin           = @$_POST['register_safe_pin'];
    
            if (isset($email_address, $password, $confirm_password, $safe_pin)) {
    
                if (filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
    
                    if ($password == $confirm_password) {
    
                        if (strlen($safe_pin) == 4 && is_numeric($safe_pin)) {
    
                            if (strlen($_POST['register_password']) > 5 && strlen($_POST['register_confirm_password']) > 5) {
    
                                $insert_user = $db->prepare("INSERT INTO `users` (`email_address`, `pwd`, `safe_pin`, `time_registered`, `activated`, `balance`, `last_login`, `ip_address`, `last_ip_address`)
                                                             VALUES (:email_address, :pwd, :safe_pin, :time_registered, :activated, :balance, :last_login, :ip_address, :last_ip_address)");
    
                                $insert_user->execute(array(
    
                                    ':email_address'        => $email_address,
                                    ':pwd'                  => $password,
                                    ':safe_pin'             => $safe_pin,
                                    ':time_registered'      => time(),
                                    ':activated'            => 0,
                                    ':balance'              => 0,
                                    ':last_login'           => 0,
                                    ':ip_address'           => $_SERVER['REMOTE_ADDR'],
                                    ':last_ip_address'      => $_SERVER['REMOTE_ADDR']
    
                                ));
    
                            }
    
                            else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your password must be a minimum of 6-characters.')); }
                        }
                        else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your safe-pin must be a 4-character numeric code.')); }
                    }
                    else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your confirmation password must match identically to your password.')); }
                }
                else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your e-mail address must be valid.  Make sure it\'s typed properly. <br />')); }
            }
            else { echo json_encode(array('result'  => '<strong>Oops!</strong> All inputs must be entered.  Double-check the form. <br />')); }
    
            break;
        }
    }
    
    if(isset($\u POST['action'])){
    开关($\u POST['action'])){
    “登记册”一案:
    $email_address=@$_POST['register_email_address'];
    $password=hash('sha512',@$_POST['register_password']);
    $confirm_password=hash('sha512',@$_POST['register_confirm_password']);
    $safe_pin=@$_POST['register_safe_pin'];
    如果(isset($email\u add
    
    ...`last_login`, `ip_address`,...
    
    if (isset($_POST['action'])) {
    
        switch($_POST['action']) {
    
        case 'register':
    
            $email_address      = @$_POST['register_email_address'];
            $password           = hash('sha512', @$_POST['register_password']);
            $confirm_password   = hash('sha512', @$_POST['register_confirm_password']);
            $safe_pin           = @$_POST['register_safe_pin'];
    
            if (isset($email_address, $password, $confirm_password, $safe_pin)) {
    
                if (filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
    
                    if ($password == $confirm_password) {
    
                        if (strlen($safe_pin) == 4 && is_numeric($safe_pin)) {
    
                            if (strlen($_POST['register_password']) > 5 && strlen($_POST['register_confirm_password']) > 5) {
    
                                $insert_user = $db->prepare("INSERT INTO `users` (`email_address`, `pwd`, `safe_pin`, `time_registered`, `activated`, `balance`, `last_login`, `ip_address`, `last_ip_address`)
                                                             VALUES (:email_address, :pwd, :safe_pin, :time_registered, :activated, :balance, :last_login, :ip_address, :last_ip_address)");
    
                                $insert_user->execute(array(
    
                                    ':email_address'        => $email_address,
                                    ':pwd'                  => $password,
                                    ':safe_pin'             => $safe_pin,
                                    ':time_registered'      => time(),
                                    ':activated'            => 0,
                                    ':balance'              => 0,
                                    ':last_login'           => 0,
                                    ':ip_address'           => $_SERVER['REMOTE_ADDR'],
                                    ':last_ip_address'      => $_SERVER['REMOTE_ADDR']
    
                                ));
    
                            }
    
                            else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your password must be a minimum of 6-characters.')); }
                        }
                        else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your safe-pin must be a 4-character numeric code.')); }
                    }
                    else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your confirmation password must match identically to your password.')); }
                }
                else { echo json_encode(array('result'  => '<strong>Oops!</strong> Your e-mail address must be valid.  Make sure it\'s typed properly. <br />')); }
            }
            else { echo json_encode(array('result'  => '<strong>Oops!</strong> All inputs must be entered.  Double-check the form. <br />')); }
    
            break;
        }
    }
    
    $("#sign_up").on('click', function() {
        $.post('./includes/ajax.php', $('#register_form').serialize() + '&action=register' , function(result) {
            var result = JSON.parse(result);
            console.log(result.result);
            $("#register_result").append(result.result);
        });
    });