Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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抛出连接错误_Php - Fatal编程技术网

前端php抛出连接错误

前端php抛出连接错误,php,Php,所以我是一个php初学者,我制作了一个带有服务器端和客户端验证的登录应用程序。当密码与db匹配后出错,或者如果电子邮件不是唯一的,我想在登录页面上抛出一个错误。 谢谢要在从DB检查后显示身份验证错误,您需要使用ajax var username = "...."; var password = "...."; $.ajax({ url: "/login", method: "POST", data:{username,password} }).done(function(

所以我是一个php初学者,我制作了一个带有服务器端和客户端验证的登录应用程序。当密码与db匹配后出错,或者如果电子邮件不是唯一的,我想在登录页面上抛出一个错误。
谢谢

要在从DB检查后显示身份验证错误,您需要使用ajax

var username = "....";
var password = "....";
$.ajax({
    url: "/login",
    method: "POST",
    data:{username,password}
}).done(function(data) {
    if(data.success){
        $("#msg").html("Success");
    }else{
        $("#msg").html(data.err_msg);
    }
});
在php文件中

<?php
    function checkAuthentication(){
        $errormsg = "";
        $result = true;
        try {
            //your data and query to check 'username' and 'password'
            if(!$password_match){
                $result = false;
                $errormsg = 'Invalid credential';
            }
        } catch (Exception $exception) {
            $result = false;
            $errormsg = 'Database error! ' . $exception->getMessage();
        }
        //return json data
        return json_encode(["success"=>$result,"err_msg"=>$errormsg]);
    }
?>


还有很多事情要做,但您可以这样想,在从DB检查后,开始显示身份验证错误,您需要使用ajax

var username = "....";
var password = "....";
$.ajax({
    url: "/login",
    method: "POST",
    data:{username,password}
}).done(function(data) {
    if(data.success){
        $("#msg").html("Success");
    }else{
        $("#msg").html(data.err_msg);
    }
});
在php文件中

<?php
    function checkAuthentication(){
        $errormsg = "";
        $result = true;
        try {
            //your data and query to check 'username' and 'password'
            if(!$password_match){
                $result = false;
                $errormsg = 'Invalid credential';
            }
        } catch (Exception $exception) {
            $result = false;
            $errormsg = 'Database error! ' . $exception->getMessage();
        }
        //return json data
        return json_encode(["success"=>$result,"err_msg"=>$errormsg]);
    }
?>


还有很多事情要做,但你可以用这种方式开始

,你的问题是?@u\u mulder,所以在检查mysql数据库后,我想在他们表格中的相应字段下面输入错误,如“错误密码”和“电子邮件已经存在”,而你的问题是?@u\u mulder,所以我想输入错误,如“错误密码”和检查mysql数据库后,在表单中的相应字段下方显示“电子邮件已存在”谢谢我将尝试此@user2486谢谢我将尝试此@user2486