• ajax注册 查询一下数据库中有时没有这个name有就被注册没有就可以使用


    HTML代码:

    <!DOCTYPE html>
    <html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="js/jquery.js"></script>

    </head>
    <script>
    $(document).ready(function(){
    $("#name").focus();
    $("#name").blur(function(){
    var a=$("#name").val();

    if (a) {
    $.post("index1ajax2.php",{"name":a},function (data){
    alert(data); //查询一下数据库中有时没有这个name有就被注册没有就可以使用
    });

    }else{

    alert("用户命不能为空");
    };


    });
    //实现注册功能
    $("#bu1").click(function(){
    var a=$("#name").val();
    var b=$("#mima").val();
    var c=$("#xingbie").val(); //val()是返回属性value对应的值
    var d=$("#xibu").val();
    var e=$("#banji").val();
    var f=$("#tex").val();

    $.post("index1.php",{"name":a,"mima":b,"xingbie":c,"xibu":d,"banji":e,"tex":f},function (data1){
    alert(data1); //弹窗

    }); //index1.php引入php文件运行这个文件 {}中间写上面var a=$("#name").val();对应的值 funtion定义个变量用alert弹窗输出

    });

    });

    </script>


    <body>
    <input type="text" id="name" placeholder="姓名" required="">
    <input type="password" id="mima" required=" " placeholder="密码至少6位数"><p></p>
    <input type="text" id="xingbie" placeholder="性别" required="">
    <input type="text" id="xibu" placeholder="系部" required="">
    <input type="text" id="banji" placeholder="班级" required="">
    <input type="text" id="tex" placeholder="电话" required="">
    <button type="button" id="bu1">确定</button>

      

    </body>

    </body>
    </html>

    index1.php代码

    <?php


    header( 'Content-Type:text/html;charset=utf-8 ');


    include_once("conn/conn.php"); //引入导入数据库控制页面

    $name=$_POST["name"];
    $mima=$_POST["mima"];
    $xingbie=$_POST["xingbie"]; // 括号里面的值对应前端里面name
    $xibu=$_POST["xibu"];
    $banji=$_POST["banji"];
    $tex=$_POST["tex"];

    $sql="INSERT into user (name,mima,xingbie,xibu,banji,tex)values('$name','$mima','$xingbie','$xibu','$banji','$tex')"; //规定查询字符串
    $r=mysqli_query($link,$sql);// $link要使用的mysql连接 $sql要查询的字符串
    if ($r) {
    echo ("写入成功");
    }else{
    echo ("失败");
    }

    ?>

    index1ajax2.php代码

    <?php


    header( 'Content-Type:text/html;charset=utf-8 ');


    include_once("conn/conn.php"); //引入导入数据库控制页面

    $name=$_POST["name"];

    $sql="SELECT*from user where name ='$name' ";
    $r=mysqli_query($link,$sql);// $link要使用的mysql连接 $sql要查询的字符串
    $n=mysqli_num_rows($r);
    if ($n>0) {
    echo "用户名被注册";
    }else{
    echo"用户名可以使用";
    }

    ?>

  • 相关阅读:
    修改python注册表
    python 调用exe程序
    python msg_box
    python pickle
    python send email
    get data from splunk
    剑指offer 14.代码的鲁棒性 链表中倒数第k个结点
    Kafka 与flume的整合
    Kafka Java API+自定义分区
    Kafka 命令行操作topic+producer+consumer详解
  • 原文地址:https://www.cnblogs.com/xinxueyou/p/7885234.html
Copyright © 2020-2023  润新知