脚本标记在php代码中不起作用,它不会创建警报表单验证

时间:2015-12-27 19:13:36

标签: javascript

这是我的代码....脚本标记在此PHP代码中无法进行表单验证。

           $get_email = "select * from users where user_email='$email'";
           $run_email = mysqli_query($con,$get_email);
           $check  = mysqli_num_rows($run_email);
              if($check==1){
               echo "<script>alert('Email is already registered!')</script>";
                exit(); 
                }
           if(strlen($pass)<8){
              echo  "<script>alert('password should be 8 character!')</script>";
               exit();
               }

1 个答案:

答案 0 :(得分:0)

好吧,我认为你需要设置javascript标签,如果你使用php来运行它,不太了解你的问题,但是,我认为可能是这样的:

<?php 
echo "<script>
        alert('Email is already registered!');
        exit();
      </script> ";

  if( strlen($pass) ) {
    echo "<script>alert('password should be 8 character!');
          exit();
          </script>" 
  }
  else { 
   $insert = "insert into users 
                (user_name,
                user_pass,
                user_email,
                user_id,user_country,
                user_gender,
                user_birthday,
                user_image,user_regis ,
                user_login date,status)

            values ('$name',
            '$pass','$email',
            '$country',
            '$Gender',
            '$user_birthday',
            'default.jpg',
            '$date', 
            '$status',
            '$posts')"; 
            $run_insert = mysqli_query($con,$insert); 
    if($run_insert){ 
        echo "<script> alert('Regisration successfull') </script>"; 
    } 
} 
?>

我真的向您推荐,使用ajax调用来选择和验证电子邮件!