CRUD实习僧 2019-11-03 13:57 采纳率: 0%
浏览 321

求大佬看下这段代码什么问题,一直提示错误

登录的代码是这样

<?php
    /** file:login.inc.php 登录系统的主控制文件和主入口文件*/ 

            /*声明一个删除Cookie的函数,调用时消除在客户端设置的所以Cookie*/
            function clearCookies(){
                //只指定Cookie识别名称一个参数,即删除客户端中这个指定名称的Cookie资料
                //生存空间默认为空,则生存期限与浏览器一样,浏览器关闭时Cookie就会被删除
                setcookie('name');
                setcookie('isLogin');
            }

            include "conn/conn.php";            
            @$username = htmlspecialchars($_POST['name']);  
            @$pwd = $_POST['pwd'];
            $pwd = md5($pwd);

            /*如果用户的操作是提交表单,则条件成立*/
        if(isset($_POST['submit'])){
            clearCookies();

            $sql = "SELECT * FROM tb_grnews WHERE name = '$name' and pwd='$pwd'";
            $res = mysql_query($sql,$link);
            /*mysql_num_rows只能用于select语句*/
            $rows=mysql_num_rows($res);
            if($rows>0){

               /*向Cookie中设置标识符为username,值是表单中提交的,期限为一周*/
               setcookie('username',$username,time()+60*60*24*7);
               /*向Cookie中设置标识符为isLogin,用来在其它页面检查用户是否登录*/
               setcookie('isLogin','1',time()+60*60*24*7);
               /*如果Cookie设置成功则转向网站首页*/
               header("Location:index.php");//跳转页面,注意路径
            }else{
                echo '<font color="red">用户名或密码错误!</font>';
            }
        }else if(@$_GET["action"]=="logout"){
            //退出时消除在客户端设置的所有Cookie
            clearCookies();
        }
?>
<html>

    <head>
        <title>登录系统</title>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="login.css" />

    </head>

    <body>
        <div class="content">

            <!--  登录面板    -->
            <div class="panel">


        <form action="login.inc.php" method="post">

                <div class="group">
                    <label for="username">用户名:</label>
                    <input id="name" type="text" name="name" placeholder="请输入账号" />
                </div>


                <div class="group">
                    <label for="pass">密码:</label>
                    <input id="pwd" type="password" name="pwd" placeholder="请输入密码" />
                </div>


                <div class="login">
                    <button type="submit" name="submit">登录</button>
                </div>
                <div class="register">
                    <input name="" type="reset" value="重置">
                </div>

        </form>

        </div>
    </body>
</html>

数据库连接的代码是这样

<?php
     $link=mysqli_connect("localhost","root","111","1024") or die("数据库连接失败".mysql_error());
     mysqli_query($link,"set names gb2312");
?>

明明输对账号密码却始终显示错误图片说明

  • 写回答

2条回答 默认 最新

  • 无双_ 2019-11-04 11:28
    关注

    上边是$username 下边是$name

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器