zoukankan      html  css  js  c++  java
  • ajax 实现密码登录

    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> //导入js包

    </head>
    <script>
    $(document).ready(function(){
    $("#but").click(function(){
    var a=$("#name").val();
    var b=$("#mima").val();


    $.post("i-ajax.php",{'name':a,'mima':b,},function(data){
    alert(data); //弹窗
    window.location.href="ajaxdonglu.php";
    }); //index1.php引入php文件运行这个文件 {}中间写上面var a=$("#name").val();对应的值 funtion定义个变量用alert弹窗输出

    });

    });

    </script>


    <body>


    <input type="text" id="name" placeholder="姓名" >
    <input type="password" id="mima" placeholder="密码至少6位数"><p></p>

    <button type="button" id="but">登录</button>

    </body>
    </html>

    PHP代码

    <?php


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


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

    $name=$_POST["name"];
    $mima=$_POST["mima"];


    $sql="SELECT*from user where name ='$name' and mima='$mima' ";
    $r=mysqli_query($link,$sql);// $link要使用的mysql连接 $sql要查询的字符串
    $n=mysqli_num_rows($r);
    if ($n>0) {
    echo "登录成功";
    }else{
    echo"登录失败";
    }

    ?>

    引入数据库的PHP代码

    <?php
    $host="localhost";//规定主机名和ip地址
    $db_user="root"; //数据库用户
    $db_pass=""; //数据库密码
    $db_name="sqlclass1"; //要使用的数据库数据库
    $timezone = "Asia/Shanghai";//上海时间

    $link=mysqli_connect($host,$db_user,$db_pass,$db_name);//mysqli_connect打开一个到 MySQL 服务器的新的连接
    mysqli_query($link,"SET names UTF8");//link 是规定要使用的mysql连接 后面是设置编码格式
    header("Content-Type: text/html; charset=utf-8");
    date_default_timezone_set($timezone); //北京时间
    ?>

  • 相关阅读:
    快速开发框架:进销存业务注意事项
    延时执行函数:前浪死在沙滩上
    新增筛选方案
    进销存数据库设计:采购订单
    SasS 设计原则十二因素
    四种线程池的解析
    高并发下的流量控制
    Mybatis 缓存机制
    谈谈JVM垃圾回收
    如何使错误日志更加方便地排查问题
  • 原文地址:https://www.cnblogs.com/xinxueyou/p/7884680.html
Copyright © 2011-2022 走看看