SoFunction
Updated on 2025-03-10

PHP implements student management system

The examples in this article share the source code of the php student management system for your reference. The specific content is as follows

Function:

1. Add/Delete/Modify
2. Data storage.

Interface distribution:

--->Main interface
--->stu Add
action ---> add/del/update in sql (process html form --> mysql's data storage && page jump)
--->stu Modification
-->Home

1.

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Student Information Management</title>
 <script>
 function doDel(id) {
  if(confirm('Confirm deletion?')) {
  ='?action=del&id='+id;
  }
 }
 </script>
</head>
<body>
<center>
 <?php
 include ("");
 ?>
 <h3>Browse student information</h3>
 <table width="500" border="1">
 <tr>
  <th>ID</th>
  <th>Name</th>
  <th>gender</th>
  <th>age</th>
  <th>class</th>
  <th>operate</th>
 </tr>
 <?php
// 1. Link to the database try{
  $pdo = new PDO("uri:","root","1");
 }catch (PDOException $e) {
  die('connection failed'.$e->getMessage());
 }
 //2.Execute sql $sql_select = "select * from stu";
 // Analysis foreach ( $pdo->query($sql_select) as $row) {
  echo "<tr>";
  echo "<th>{$row['id']} </th>";
  echo "<th>{$row['name']}</th>";
  echo "<th>{$row['sex']} </th>";
  echo "<th>{$row['age']} </th>";
  echo "<th>{$row['classid']}</th>";
  echo "<td>
   <a href='?id={$row['id']}'>Revise</a>
   <a href='javascript:void(0);' onclick='doDel({$row['id']})'>delete</a>
  </td>";
  echo "</tr>";
 }
 ?>
 </table>
</center>
</body>
</html>

2.

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Student Management System</title>
</head>
<body>
<center>
 
 <?php include (''); ?>
 <h3>Increase student information</h3>
 <form action="?action=add" method="post">
 <table>
  <tr>
  <td>Name</td>
  <td><input type="text" name="name"></td>
  </tr>
  <tr>
  <td>age</td>
  <td><input type="text" name="age"></td>
  </tr>
  <tr>
  <td>gender</td>
  <td><input type="radio" name="sex" value="male">male</td>
  <td><input type="radio" name="sex" value="female">female</td>
  </tr>
  <tr>
  <td>class</td>
  <td><input type="text" name="classid"></td>
  </tr>
  <tr>
<!--  <td> </td>-->
  <td><a href="">return</td>
  <td><input type="submit" value="Add to"></td>
  <td><input type="reset" value="Reset"></td>
  </tr>
 </table> 
 </form>
 
</center>
</body>
</html>

3.

<?php
/**
  * Created by PhpStorm.
  * User: hyh
  * Date: 16-7-7
  * Time: 9:37 pm
  */
//1. Link to the databasetry{
 $pdo = new PDO("uri:","root","1");
}catch (PDOException $e) {
//  echo 'Connection failed: ' . $e->getMessage();
 die('connection failed'.$e->getMessage());
}
 
// Do the correct value 
switch ($_GET['action']){
 
 case 'add'://add 
 $name = $_POST['name'];
 $sex = $_POST['sex'];
 $age = $_POST['age'];
 $classid = $_POST['classid'];
  
 $sql = "insert into stu (name, sex, age, classid) values ('{$name}', '{$sex}','{$age}','{$classid}')";
 $rw = $pdo->exec($sql); 
 if ($rw > 0){
  echo "<script>alter('Added successfully');</script>";
 }else{
  echo "<script>alter('Add failed');</script>";
 }
 header('Location: ');
 break; 
 
 case 'del'://get
 $id = $_GET['id'];
 $sql = "delete from stu where id={$id}";
 $rw = $pdo->exec($sql);
 if ($rw > 0){
  echo "<script>alter('Delete successfully');</script>";
 }else{
  echo "<script>alter('Delete failed');</script>";
 }
 header('Location: ');
 break;
 
 case 'edit'://post
 $id = $_POST['id'];
 $name = $_POST['name']; 
 $age = $_POST['age'];
 $classid = $_POST['classid'];
 $sex = $_POST['sex'];
  
// echo $id, $age, $age, $name;
 $sql = "update stu set name='{$name}', age={$age},sex='{$sex}',classid={$classid} where id={$id};";
// $sql = "update set name='jike',sex='female', age=24,classid=44 where id=17"; print $sql;
 $rw = $pdo->exec($sql);
 if ($rw > 0){
  echo "<script>alter('Update successfully');</script>";
 }else{
  echo "<script>alter('Update failed');</script>";
 }
 header('Location: ');
 break; 
 
 default:
 header('Location: ');
 break;
}

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Student Management System</title>
</head>
<body>
<center>
 <?php include ('');
 //1. Link to the database try{
 $pdo = new PDO("uri:","root","1");
 }catch (PDOException $e) {
 die('connection failed'.$e->getMessage());
 }
 //2.Execute sql $sql_select = "select * from stu where id={$_GET['id']}";
 $stmt = $pdo->query($sql_select);
 if ($stmt->rowCount() >0) {
 $stu = $stmt->fetch(PDO::FETCH_ASSOC); // Analyze data }else{
 die("no have this id:{$_GET['id']}");
 }
 ?>
 
 <h3>Modify student information</h3>
 
 <form action="?action=edit" method="post">
 <input type="hidden" name="id" value="<?php echo $stu['id'];?>">
 <table>
  <tr>
  <td>Name</td>
  <td><input type="text" name="name" value="<?php echo $stu['name'];?>"></td>
  </tr>
  <tr>
  <td>age</td>
  <td><input type="text" name="age" value="<?php echo $stu['age'];?>"></td>
  </tr>
  <tr>
  <td>gender</td>
  <td>
   <input type="radio" name="sex" value="male" <?php echo ($stu['sex'] == "male")? "checked":"";?> >male
  </td>
  <td>
   <input type="radio" name="sex" value="female" <?php echo ($stu['sex'] == "female")? "checked":"";?> >female
  </td>
  </tr>
  <tr>
  <td>class</td>
  <td><input type="text" name="classid" value="<?php echo $stu['classid']?>"></td>
  </tr>
  <tr>
  <td> </td>
  <td><input type="submit" value="renew"></td>
  <td><input type="reset" value="Reset"></td>
  </tr>
 </table>
 </form>
 
 
</center>
 
<?php
?>
</body>
</html>

5.

<!DOCTYPE html>
<html lang="en">
<body>
 <h2>Student Management System</h2>
 <a href=""> Browse students</a>
 <a href=""> Add students</a>
 <hr>
</body>
</html>

For more study materials, please pay attention to the special topic "Management system development》。

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.