首页  >  问答  >  正文

在开发注册系统时,代码已写好,但页面显示如下

IMG_0090.JPG

<?php

 session_start();

 header("Content-type:text/html;charset=utf-8");

 $link = mysqli_connect('localhost','123654lgh','etjyr2bm','123654lgh');

 if (!$link) {

  die("连接失败:".mysqli_connect_error());

}

$sql = "select * from login";

$result = mysqli_query($link, $sql);

$rows = mysqli_fetch_array($result);

 

 $username = $_POST['username'];

 $password = $_POST['password'];

 $confirm = $_POST['confirm'];

 $email = $_POST['email'];

 

 if($username == "" || $password == "" || $confirm == "" || $email == "")

     if ((strlen($username) < 3)||(!preg_match('/^\w+$/i', $username)))

 {

 echo "<script>alert('信息不能为空!重新填写');window.location.href='zhuce.html'</script>";

 } elseif ((strlen($username) < 3)||(!preg_match('/^\w+$/i', $username))) {

 echo "<script>alert('用户名至少3位且不含非法字符!重新填写');window.location.href='zhuce'</script>";

 //判断用户名长度

 }elseif(strlen($password) < 5){

 echo "<script>alert('密码至少5位!重新填写');window.location.href='zhuce.html'</script>";

 //判断密码长度

 }elseif($password != $confirm) {

 echo "<script>alert('两次密码不相同!重新填写');window.location.href='zhuce.html'</script>";

 //检测两次输入密码是否相同

 } elseif (!preg_match('/^[\w\.]+@\w+\.\w+$/i', $email)) 

 echo "<script>alert('邮箱不合法!重新填写');window.location.href='zhuce.html'</script>";

 //判断邮箱格式是否合法

 elseif(mysqli_fetch_array(mysqli_query($link,"select * from login where username = '$username'"))){

 echo "<script>alert('用户名已存在');window.location.href='zhuce.html'</script>";

 } else{

 $sql= "insert into login(username, password, confirm, email)values('$username','$password','$confirm','$email')";

 //插入数据库

 if(!(mysqli_query($link,$sql))){

 echo "<script>alert('数据插入失败');window.location.href='zhuce.html'";

 }else{

 echo "<script>alert('注册成功');window.location.href='yonghu.html'</script>";

 }

}

?>


李壬李壬1948 天前993

全部回复(1)我来回复

  • kanglecheng

    kanglecheng2019-07-12 14:22:26

    这是客户端的提示,你页面上用表单提交了,然后你刷新就会有的提示,不是的代码报错问题

    回复
    0
  • 取消回复