Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.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
Javascript 如何在php中显示登录屏幕中的警报框。如果用户输入';这段代码的密码或用户名有误_Javascript_Php_Html - Fatal编程技术网

Javascript 如何在php中显示登录屏幕中的警报框。如果用户输入';这段代码的密码或用户名有误

Javascript 如何在php中显示登录屏幕中的警报框。如果用户输入';这段代码的密码或用户名有误,javascript,php,html,Javascript,Php,Html,如何在php中显示登录屏幕中的警报框 如果用户为此代码输入了错误的密码或用户名 if(isset( $_POST['email'])){ $email = $_POST['email']; $cpassword = $_POST['cpassword']; include ("../backend/user.php"); $c = new customer(); //Assign username & password from post met

如何在php中显示登录屏幕中的警报框

如果用户为此代码输入了错误的密码或用户名

if(isset( $_POST['email'])){
    $email = $_POST['email'];
    $cpassword = $_POST['cpassword'];

    include ("../backend/user.php");
    $c = new customer();
    //Assign username & password from post method to a varibale
    $res = $c->customer_login($email,$cpassword);
    if($res == true){
      //Direct the user to appropriate page 
      header("location:../views/profile.php");
    }else{

      include ("../backend/admin.php");
      $a = new admin();
      //Assign username & password from post method to a varibale
      $res = $a->admin_login($email,$cpassword);
      if($res == true){
        //Direct the user to appropriate page 
        header("location:../views/admin.php");
      }
    }
    //Display message invalid user name or password
    $message = "invalid username or password";
  }

您可以使用Javascript:

$message=“无效的用户名或密码”

echo“警报('$message')

php在服务器上运行-您不能在服务器上发出警报(php无论如何都没有警报功能)并期望客户端在浏览器中看到警报是的,您可以通过在phpCheck登录php AJAX中注入javascript代码为例
 echo "<script type='text/javascript'>alert('$message');</script>"