sql 注入代码例子 --mysql --

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<html>
<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
</head>
<body>

<form action="welcome.php" method="get">
    name: <input type="text" name="name">
	 password: <input type="text" name="password">

    <input type="submit" value="提交">
</form>

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

 

welcome.php

 

<?php

$sss =0;
$servername = "localhost";
$username = "root";
$password = "root";

$conn = mysqli_connect($servername, $username, $password);

// 检测连接
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
//echo "连接成功";
$name =$_REQUEST['name'];
$password =$_REQUEST['password'];


if (!isset($name) ||  !isset($password))
{
    return;
}

//example 1
 $sql = "SELECT id, username, password FROM test.user where username = '$name'  and password ='$password' ;";


//example 2
 

echo $sql . '<br>';

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    echo 'get succ ' . '<br>';
    // 输出数据
    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["username"]. " ;password " . $row["password"]. "<br>";
    }
} else {
    echo "0 结果";
}

mysqli_close($conn);


?>

 

 

sql

INSERT INTO `user` VALUES (1, 'admin', 'admin');
INSERT INTO `user` VALUES (2, 'aaa', 'bbb');
INSERT INTO `user` VALUES (3, 'ccc', 'ddd');
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值