php学生信息管理系统代码
时间: 2023-09-09 14:11:59 浏览: 44
很抱歉,我不是一个能够提供代码的程序。但是,以下是一个简单的PHP学生信息管理系统的示例程序,希望可以帮到你:
```php
<!DOCTYPE html>
<html>
<head>
<title>学生信息管理系统</title>
</head>
<body>
<h1>学生信息管理系统</h1>
<?php
// 连接数据库
$con = mysqli_connect("localhost","root","","student_info");
// 检查连接是否成功
if (mysqli_connect_errno()){
echo "连接失败: " . mysqli_connect_error();
}
// 添加学生信息
if(isset($_POST['add'])){
$name = $_POST['name'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$sql = "INSERT INTO students(name, age, gender) VALUES ('$name', '$age', '$gender')";
if(mysqli_query($con, $sql)){
echo "添加成功!";
} else {
echo "添加失败: " . mysqli_error($con);
}
}
// 显示学生信息
$sql = "SELECT * FROM students";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result) > 0){
echo "<table border='1'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>姓名</th>";
echo "<th>年龄</th>";
echo "<th>性别</th>";
echo "</tr>";
while($row = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "没有学生信息.";
}
// 关闭连接
mysqli_close($con);
?>
<h2>添加学生信息</h2>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label>姓名:</label>
<input type="text" name="name">
<br>
<label>年龄:</label>
<input type="text" name="age">
<br>
<label>性别:</label>
<input type="radio" name="gender" value="男">男
<input type="radio" name="gender" value="女">女
<br>
<input type="submit" name="add" value="添加">
</form>
</body>
</html>
```
以上代码只是一个简单的示例,你可以根据自己的需求进行修改和完善。同时,需要注意的是,代码中的数据库连接信息需要根据你的实际情况进行修改。