码迷,mamicode.com
首页 > 其他好文 > 详细

注册界面

时间:2020-03-01 20:11:54      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:put   add   scale   url   insert   success   blur   console   root   

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
</head>

<body>
    <?php
    if ($_POST) {
        $name = trim($_POST[‘name‘]);
        $pasd = md5(trim($_POST[‘pasd‘]));
        $conn = new mysqli(‘localhost‘, ‘root‘, ‘root‘, ‘aaa‘);
        if ($conn->connect_error) {
            echo $conn->error;
        } else {
            // 判断用户是否已经注册
            $sql = "select * from kaoshi where name = ‘$name‘";
            $res = $conn->query($sql);
            $sql = "insert into kaoshi(name,mima) values(‘$name‘,‘$pasd‘)";
            if ($res->num_rows > 0) {
                echo ‘用户已注册‘;
            } else {
                $res = $conn->query($sql);
                if ($res) {
                    echo ‘注册成功‘;
                } else {
                    echo ‘注册失败‘;
                }
            };
        }
        $conn->close();
    }
    ?>
    <form action="" method="post" onsubmit="return sub();" enctype="multipary/from-data">
        用户名:<input type="text" name="name" id="name">
        <p id="a"></p>
        <br>
        密码:<input type="password" name="pasd" id="pasd">
        <br>
        <a href="http://www.q.com/denglu.php">返回登入</a>
        <input type="submit" value="注册">
    </form>
</body>
<script src="js/jquery-3.4.1.js"></script>
<!-- 判断用户密码的长度 -->
<script>
    // 失去焦点时间
    $(‘#name‘).blur(function(){
        var vals =$(‘#name‘).val();
        $.ajax({
            url:‘ajax.php‘,
            type:‘post‘,
            async:false,  //true异步处理//false同步处理
            data: {‘val‘:vals,‘id‘:3},
            dataType: ‘json‘,
            success: function(res){
                console.log(res);
                if(res.row>0){
                    $(‘#a‘).text(‘用户名已注册‘);
                    $(‘#uname‘).addClass(‘iszhuce‘);
                }
            }
        });
        $(‘#a‘).text(‘用户已注册‘)
    })
    function sub(){
        var i = $(‘#name‘).val();
        var pad = $(‘pasd‘).val();
        if(!i){
            alert(‘用户名必填‘);
            return false;
        }
        if(!pad){
            alert(‘密码必填‘);
            return false;
        }
        if(i.lenght >6){
            return true;
        }else{
            alert(‘用户名长度不够‘);
            return false;
        };
        if(pad.lenght >8){
            return true;
        }else{
            alert(‘密码长度不够‘);
            return false;
        }
    };
</script>
</html>

  

注册界面

标签:put   add   scale   url   insert   success   blur   console   root   

原文地址:https://www.cnblogs.com/wangzihao147/p/12391423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!