3.5、后端开发基础PHP - PHP简介及PHP基本函数(下) - 已锁定

reset   ·   发表于 2018-06-01 16:16:41   ·   CTF&WP专版
c.php
<?php
    $db_name="test";//数据库
    $server_name="localhost";//服务器
    $conn=mysqli_connect($server_name,"root","",$db_name);//链接数据库
    if(!$conn)//连不上数据库
    {
        die("连接错误" . mysqli_connect_error()); 
        exit;
    }
    
    $curDb=mysqli_select_db($conn,$db_name);//选择数据库
    if(!$curDb)//数据库不存在
    {
        die("不存在" . $db_name); 
        exit;
    }
    $user_name=$_GET['user_name'];//获取用户名和密码
    $password=$_GET['password'];
    $denglu="select user_name,password from users where user_name='" . $user_name ;
    echo $denglu ;
    
    if($user_name)
    {
        $result=mysqli_query($conn,$denglu);//执行sql语句查询用户名
        $rows=mysqli_num_rows($result);//遍历查询结果
        if($rows)
        {
            $denglu2="select user_name,password from users where user_name='" . $user_name . "' and password = '" . $password . "'"; 
			$result2=mysqli_query($conn,$denglu2);//执行sql语句查询用户名
            $rows2=mysqli_num_rows($result2);//遍历查询结果
			if($rows)
			{ echo "登陆成功!";}
			else
			{ echo "密码错误!";}	
        }
        else
        {
            echo "用户不存在";
            exit;
        }
    }
    else
    {
        echo "用户名或密码错误!";
    }
?>


c.html
<!DOCTYPE html>
<html>
<head>
<title>login</title>
</head>
<body>
        <form  action="c.php" method="get">
            <h3>User name:</h3>
            <input type="text" name="user_name"/>
            </br></br>
            <h3>password:</h3>
            <input type="text" name="password">
            </br></br>
            <input type="submit">
        </form>
</body>
</html>


打赏我,让我更有动力~

1 条回复   |  直到 2018-6-3 | 1410 次浏览

Track-方丈
发表于 2018-6-3

通过

评论列表

  • 加载数据中...

编写评论内容
登录后才可发表内容
返回顶部 投诉反馈

© 2016 - 2024 掌控者 All Rights Reserved.