DAY5 php + mysql 写一个简单的sql注入平台

php mysql 在浏览器输入用户名,去数据库查询。查到则显示在浏览器,查不到则显示空。

sql 里面三个字段 id username password

create table t1 (id int(3) NOT NULL AUTO_INCREMENT,username char(10) NOT NULL,password varchar(20));

insert into t1 values(1,'hello','world');

index.php

//php mysql 在浏览器输入用户名,去数据库查询。查到则显示在浏览器,查不到则显示空。
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>查询页面</title>
    </head>

     <body>

<form name="form" method="post" action="select.php">    
            <center>
            <table>
                <tr>
                    <td><br>请输入用户名:<input type="text" name="username"></td>
                </tr>
                <tr>
                </tr>
                <tr>
                    <td><br><input type="submit"  value="查询">    <input type="reset" value="重置"></td>
                     
                </tr>
                </br>
                <br>
                    <br>
                    输入用户名能够查询到密码,如果不知道请使用sql注入测试
            </table>
            </center>
        </form>
</body>
</html>

select.php

//php mysql 在浏览器输入用户名,去数据库查询。查到则显示在浏览器,查不到则显示空。
<?php
error_reporting(E_ALL || ~E_NOTICE);
$con = mysql_connect("localhost","wyl","123456");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("wyl", $con);
$nm = $_POST['username'];
$result = mysql_query("  SELECT * FROM t1 where username='".$nm."' ");
echo "<table >
<tr>
<th>username</th>
<th>password</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
            echo "<tr>";
            echo "<td>" . $row['username'] . "</td>";
            echo "<td>" . $row['password'] . "</td>";
            echo "</tr>";
  }
echo "</table>";
mysql_close($con);
?>