-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<meta charset="utf-8"> | ||
<head> | ||
<title>学生信息录入</title> | ||
</head> | ||
<body> | ||
<h2>学生信息录入</h2> | ||
|
||
<form method="POST" action="add.php"> | ||
<label for="name">姓名:</label> | ||
<input type="text" id="name" name="name" required><br><br> | ||
|
||
<label for="age">年龄:</label> | ||
<input type="number" id="age" name="age" required><br><br> | ||
|
||
<label for="gender">性别:</label> | ||
<select id="gender" name="gender" required> | ||
<option value="男">男</option> | ||
<option value="女">女</option> | ||
</select><br><br> | ||
|
||
<input type="submit" value="提交"> | ||
</form> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
$servername = "localhost"; // 数据库服务器名称 | ||
$username = "students"; // 数据库用户名 | ||
$password = "123456"; // 数据库密码 | ||
$dbname = "students"; // 数据库名称 | ||
|
||
// 创建连接 | ||
$conn = new mysqli($servername, $username, $password, $dbname); | ||
|
||
if ($_SERVER["REQUEST_METHOD"] == "POST") { | ||
// 从表单获取学生信息 | ||
$name = $_POST["name"]; | ||
$age = $_POST["age"]; | ||
$gender = $_POST["gender"]; | ||
|
||
// 构建插入SQL语句 | ||
$sql = "INSERT INTO student_info (name, age, gender) | ||
VALUES ('$name', $age, '$gender')"; | ||
|
||
// 执行插入操作 | ||
if ($conn->query($sql) === TRUE) { | ||
echo "学生信息添加成功"; | ||
} else { | ||
echo "添加学生信息时出现错误: " . $conn->error; | ||
} | ||
} | ||
|
||
// 关闭数据库连接 | ||
$conn->close(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
$servername = "localhost"; // 数据库服务器名称 | ||
$username = "students"; // 数据库用户名 | ||
$password = "123456"; // 数据库密码 | ||
$dbname = "students"; // 数据库名称 | ||
|
||
// 创建连接 | ||
$conn = new mysqli($servername, $username, $password, $dbname); | ||
|
||
// 检查连接是否成功 | ||
if ($conn->connect_error) { | ||
die("连接数据库失败: " . $conn->connect_error); | ||
} | ||
else | ||
{ | ||
echo "数据库连接成功!"; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<meta charset="utf-8"> | ||
<head> | ||
<title>学生信息删除</title> | ||
</head> | ||
<body> | ||
<h2>学生信息删除</h2> | ||
|
||
<form method="POST" action="del.php"> | ||
<label for="name">学生姓名:</label> | ||
<input type="text" id="name" name="name" required><br><br> | ||
|
||
<input type="submit" value="删除"> | ||
</form> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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 = "DELETE FROM student_info WHERE name='$name'"; | ||
|
||
// 执行删除操作 | ||
if ($conn->query($sql) === TRUE) { | ||
echo "学生信息删除成功"; | ||
} else { | ||
echo "删除学生信息时出现错误: " . $conn->error; | ||
} | ||
} | ||
|
||
// 关闭数据库连接 | ||
$conn->close(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>编辑学生信息</title> | ||
<script> | ||
function fillName() { | ||
var name = decodeURIComponent(window.location.search.substring(1).split("=")[1]); | ||
document.getElementById("name").value = name; | ||
} | ||
</script> | ||
</head> | ||
<body onload="fillName()"> | ||
<h2>编辑学生信息</h2> | ||
|
||
<form action="edit.php" method="post"> | ||
姓名: <input type="text" id="name" name="name" readonly> <br> | ||
年龄: <input type="text" name="age"> <br> | ||
性别: <input type="text" name="gender"> <br> | ||
<input type="submit" value="保存"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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"]; | ||
$age = $_POST["age"]; | ||
$gender = $_POST["gender"]; | ||
|
||
// 构建更新SQL语句 | ||
$sql = "UPDATE student_info SET age=$age, gender='$gender' WHERE name='$name'"; | ||
|
||
// 执行更新操作 | ||
if ($conn->query($sql) === TRUE) { | ||
echo "学生信息修改成功"; | ||
} else { | ||
echo "修改学生信息时出现错误: " . $conn->error; | ||
} | ||
} | ||
|
||
// 关闭数据库连接 | ||
$conn->close(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>学生信息管理系统</title> | ||
</head> | ||
<body> | ||
<h2>欢迎来到学生信息管理系统</h2> | ||
|
||
<button onclick="window.location.href='add.html'">添加学生信息</button> | ||
<button onclick="window.location.href='del.html'">删除学生信息</button> | ||
<button onclick="window.location.href='query.html'">查询学生信息</button> | ||
<button onclick="window.location.href='query_update.html'">修改学生信息</button> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>查询学生信息</title> | ||
</head> | ||
<body> | ||
<h2>查询学生信息</h2> | ||
<form action="query.php" method="post"> | ||
输入要查询的学生姓名: | ||
<input name="name" type="text" size="10" > | ||
<br /> | ||
<input name="submit" type="submit" value="查询学生信息" /> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?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>"; | ||
} | ||
} else { | ||
echo "<br>没有找到相关学生信息"; | ||
} | ||
} | ||
|
||
// 关闭数据库连接 | ||
$conn->close(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>修改学生信息</title> | ||
</head> | ||
<body> | ||
<h2>查询你所要修改的学生信息</h2> | ||
<form action="query_update.php" method="post"> | ||
输入要修改的学生姓名: | ||
<input name="name" type="text" size="10" > | ||
<br /> | ||
<input name="submit" type="submit" value="查询学生信息" /> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> |