zoukankan      html  css  js  c++  java
  • PHP语言 -- Ajax 注册用户名是否可用

    <body>
    <h1>注册</h1>
    <div><input type="text" id="user" /><div></div></div>
    </body>
    
    <script type="text/javascript">
    
    $(document).ready(function(e){
    
    //判断用户名是否可用
    $("#user").blur(function(){
    
    var uid = $(this).val();
    
    $.ajax({
    
    url:"chuli.php",
    data:{u:uid,type:1},
    type:"POST",
    datatype:"TEST"
    success:function(d){
    
    if(d=="OK")
    {
    $("$ts").html("用户名可用");
    }
    else
    {
    $("#ts").html("<span style='color=red'>该用户名已经存在</span>");
    } } }); }) });
    </script>

     chuli.php

    <?php  //不要有空 顶到头写
    
    $type=$_POST["type"];
    
    include "DBDA.php";
    
    $db = new DBDA();
    
    switch($type)
    {
    case 0:
    
    $uid = $_POST["u"]; //接收
    $pwd = $_POST["p"];
    
    
    $sql = "select count(*) from login where username='{$uid}' and password='{$pwd}'";
    
    $attr = $db->Query($sql);
    
    if($attr[0][0]==0)
    {
    echo "用户名密码不正确";
    }
    else
    {
    echo "OK";
    }
    
    break;
    case 1:
    
    $uid = $_POST["u"];
    
    $sql = "select count(*) from login where username='{$uid}'";
    
    $attr = $db->Query($sql);
    
    if($attr[0][0]==0)
    {
    echo "OK";
    }
    else
    {
    echo "NO";
    }
    
    break;
    }
  • 相关阅读:
    axios 封装
    Git 常用命令行
    React Native 开发环境搭建
    React Native 组件分类
    日期插件rolldate.js的使用
    单图片上传
    使用css完成物流进度的样式
    搜索过滤 以及排序
    v-for的使用方法
    v-if 和v-show 用法
  • 原文地址:https://www.cnblogs.com/yifangtongxing/p/5430415.html
Copyright © 2011-2022 走看看