Home  >  Article  >  Backend Development  >  PHP implements student management system

PHP implements student management system

不言
不言Original
2018-06-12 17:32:4322402browse

This article mainly introduces the specific implementation code of the PHP student management system in detail. Interested friends can refer to it.

The example in this article shares the source code of the PHP student management system for everyone. For reference, the specific content is as follows

Function:
1.Add/Delete/Modify
2.Data storage.
Interface distribution:
index.php --->Main interface
add.php --->stu add
action ---> add/del/update in sql (processing html form-->mysql Data storage && page jump)
edit.php --->stu modify
menu.php -->Homepage

1. index.php




 
 学生信息管理
 

浏览学生信息

getMessage()); } //2.执行sql $sql_select = "select * from stu"; //3.data 解析 foreach ( $pdo->query($sql_select) as $row) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } ?>
ID 姓名 性别 年龄 班级 操作
{$row['id']} {$row['name']}{$row['sex']} {$row['age']} {$row['classid']} 修改 删除

2. add.php




 
 学生管理系统

增加学生信息

姓名
年龄
性别
班级
返回

3. action.php

##

getMessage();
 die('connection failed'.$e->getMessage());
}
 
//2.action 的值做对操作
 
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 "";
  }else{
   echo "";
  }
  header('Location: index.php');
  break; 
  
 case 'del'://get
  $id = $_GET['id'];
  $sql = "delete from stu where id={$id}";
  $rw = $pdo->exec($sql);
  if ($rw > 0){
   echo "";
  }else{
   echo "";
  }
  header('Location: index.php');
  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 myapp.stu set name='jike',sex='女', age=24,classid=44 where id=17";
  print $sql;
  $rw = $pdo->exec($sql);
  if ($rw > 0){
   echo "";
  }else{
   echo "";
  }
  header('Location: index.php');
  break; 
  
 default:
  header('Location: index.php');
  break;
}

4.edit.php




 
 学生管理系统

getMessage()); } //2.执行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); // 解析数据 }else{ die("no have this id:{$_GET['id']}"); } ?>

修改学生信息

姓名
年龄
性别 >男 >女
班级

5. menu.php




 

学生管理系统

浏览学生 添加学生

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Analysis of the pessimistic locking mechanism implemented by PHP and redis

The above is the detailed content of PHP implements student management system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn