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');