• 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); //北京时间
    ?>

  • 相关阅读:
    关于使用modelsim的一点感想
    matlab与modelsim中的文件操作函数
    几种测距定位方法
    关于数字信号处理中的一些概念的理解
    转载 关于case语句的优先级
    转载 关键路径优化实例
    转载 寄存器平衡实例
    第八篇:并发回射服务器的最基本实现思路
    第七篇:几个经典的TCP通信函数
    第六章:表达格式和数值格式的转换
  • 原文地址:https://www.cnblogs.com/xinxueyou/p/7884680.html
Copyright © 2020-2023  润新知