-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_update.php
47 lines (39 loc) · 1.48 KB
/
query_update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$servername = "localhost"; // 数据库服务器名称
$username = "students"; // 数据库用户名
$password = "123456"; // 数据库密码
$dbname = "students"; // 数据库名称
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查连接是否成功
if ($conn->connect_error) {
die("连接数据库失败: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 从表单获取学生姓名
$name = $_POST["name"];
// 构建查询SQL语句
$sql = "SELECT * FROM student_info WHERE name='$name'";
// 执行查询操作
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// 输出查询结果和编辑按钮
while ($row = $result->fetch_assoc()) {
echo "<br>";
echo "ID: " . $row["id"] . "<br>";
echo "姓名: " . $row["name"] . "<br>";
echo "年龄: " . $row["age"] . "<br>";
echo "性别: " . $row["gender"] . "<br>";
// 在编辑页面中自动填充学生姓名
echo "<a href=\"edit.html?name=" . urlencode($row["name"]) . "\">编辑</a>";
echo "<br>";
}
} else {
echo "<br>没有找到相关学生信息";
}
}
// 关闭数据库连接
$conn->close();
?>
</body>
</html>