Files
AutoLoginLWsWeb/20241208/search_73.php
2025-01-07 17:55:50 +08:00

44 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>姓名查询</title>
</head>
<body>
<form method="POST" action="search_73.php">
<label for="search_name">姓名查询:</label>
<input type="text" id="search_name" name="search_name" required>
<input type="submit" id="ok" name="ok" value="ok">
</form>
<?php
include_once 'db_config.php';
// 检查表单是否提交
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['search_name'])) {
// 获取表单输入的姓名
$searchName = $_POST['search_name'];
// 设置字符集
mysqli_set_charset($link, "utf8");
// 准备查询语句使用准备语句以防SQL注入
$query = $link->prepare("SELECT address FROM user_70 WHERE name = ?");
$query->bind_param("s", $searchName);
$query->execute();
$result = $query->get_result();
if ($result->num_rows > 0) {
// 输出查询结果
while ($row = $result->fetch_assoc()) {
echo "<p>地址: " . htmlspecialchars($row['address']) . "</p>";
}
} else {
// 在没有查询到结果时显示
echo "<p>查无此人</p>";
}
}
?>
</body>
</html>