Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php I';如果电子邮件存在,我试图传递一个错误,然后发送一个错误,说它存在于AJAX中,但代码不是';不行吗?_Php_Jquery_Arrays_Json_Ajax - Fatal编程技术网

Php I';如果电子邮件存在,我试图传递一个错误,然后发送一个错误,说它存在于AJAX中,但代码不是';不行吗?

Php I';如果电子邮件存在,我试图传递一个错误,然后发送一个错误,说它存在于AJAX中,但代码不是';不行吗?,php,jquery,arrays,json,ajax,Php,Jquery,Arrays,Json,Ajax,这是我为ajax编写的代码,每件事都可以工作,但它不会发送电子邮件中存在的错误。当我在控制台日志中查看createuser.php页面时,它给出了错误 $(document).ready(function(){ $("#signup_button").click(function(){ if (!$("#terms").is(":checked")){ alert("you must agree to terms"); return false;

这是我为ajax编写的代码,每件事都可以工作,但它不会发送电子邮件中存在的错误。当我在控制台日志中查看createuser.php页面时,它给出了错误

$(document).ready(function(){
$("#signup_button").click(function(){
    if (!$("#terms").is(":checked")){
        alert("you must agree to terms");
        return false;
    }
    $.ajax({
        url: "system/api/createuser.php",
        type: "post",

        data: {email: $("#signup_email").val(), name: $("#signup_name").val(), password: $("#signup_password").val()}
    }).done(function(response){
        var resp = $.parseJSON(response);
        if (resp.errors != ""){
            alert(resp.errors);
        }else{

        }

       });
    });
});
这是createuser.php的php代码

<?php
include ("../include.php");
$return = array();
$email = $_POST['email'];
$password = $_POST['password'];
$name = $_POST['name'];

$user = User::createuser($email, $password, $name, 1,1,1,1,1,1,1,1,1,2,2,0);

if ($user == false){
    $return['errors'] = "A user with that email exits!!";
}else{
    $return = "";
    $_SESSION['user'] = $user;
    echo "This is a test: " . $user->email . "   " . $user->name . "\n";
}
echo json_encode($return);
?>

你的问题只有一半的代码php看起来像什么?您在控制台中看到了什么错误?另外,您是否在浏览器的开发工具中看到了响应?你能分享吗?你确定当用户存在时,
User::createuser()
返回false吗?在控制台日志中,这是我收到的消息。我收到了我的错误,但没有在页面上提醒我。警报(“该用户已存在!!”;{errors:“有该电子邮件的用户退出!!”}errors:“有该电子邮件的用户退出!!”
    global  $db, $user_id;
    // check that email is active //

    $check = $db->query("SELECT * From users where email = '".$email."'");
    $check21 = $db->fetch($check);

    if(isset($check21['email'])){
        return false;
        $db->error("user exits");
    }else{
        $check2 = $db->fetch($check);
        $options = [
    'cost' => 11,
    'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
    ];
    $hashed_password = password_hash($password, PASSWORD_BCRYPT, $options);



    $user_created = $db->query("INSERT INTO users (email, password, name, strength, creativity, stealth, integrity, investigation, charm, fundraising, intimidation, manipulation, job_id, party_id, admin) VALUES  ('$email','$hashed_password', '$name', 
                '$strength','$creativity', '$stealth', '$integrity',
                '$investigation', '$charm', '$fundraising', '$intimidation',
                '$manipulation', '$job', '$party', '$admin' )");


            if($user_created == true){

                $users = $db->fetch($db->query("SELECT user_id From users where email='".$email."' ") );
                $user_id = $users['user_id'];

                return new User($user_id);
            }elseif($user_created == false)
                return false;
            }else{
                return false;
            }
    }