php 학생 관리 시스템 구현

본 논문 의 사례 는 phop 학생 관리 시스템 의 소스 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.
기능:
1.추가/삭제/수정
2.데이터 저장.
인터페이스 분포:
index.php--->메 인 인터페이스
add.php--->stu 추가
action--->sql 에서 add/del/update(html 폼 처리-->my sql 의 데이터 저장&페이지 전환)
edit.php--->stu 수정
menu.php-->첫 페이지
1. index.php

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>      </title>
 <script>
 function doDel(id) {
  if(confirm('    ?')) {
  window.location='action.php?action=del&id='+id;
  }
 }
 </script>
</head>
<body>
<center>
 <?php
 include ("menu.php");
 ?>
 <h3>      </h3>
 <table width="500" border="1">
 <tr>
  <th>ID</th>
  <th>  </th>
  <th>  </th>
  <th>  </th>
  <th>  </th>
  <th>  </th>
 </tr>
 <?php
// 1.      
 try{
  $pdo = new PDO("uri:mysqlPdo.ini","root","1");
 }catch (PDOException $e) {
  die('connection failed'.$e->getMessage());
 }
 //2.  sql
 $sql_select = "select * from stu";
 //3.data   
 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='edit.php?id={$row['id']}'>  </a>
   <a href='javascript:void(0);' onclick='doDel({$row['id']})'>  </a>
  </td>";
  echo "</tr>";
 }
 ?>
 </table>
</center>
</body>
</html>
2. add.php

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>      </title>
</head>
<body>
<center>
 
 <?php include ('menu.php'); ?>
 <h3>      </h3>
 <form action="action.php?action=add" method="post">
 <table>
  <tr>
  <td>  </td>
  <td><input type="text" name="name"></td>
  </tr>
  <tr>
  <td>  </td>
  <td><input type="text" name="age"></td>
  </tr>
  <tr>
  <td>  </td>
  <td><input type="radio" name="sex" value=" "> </td>
  <td><input type="radio" name="sex" value=" "> </td>
  </tr>
  <tr>
  <td>  </td>
  <td><input type="text" name="classid"></td>
  </tr>
  <tr>
<!--  <td>&nbsp;</td>-->
  <td><a href="index.php">  </td>
  <td><input type="submit" value="  "></td>
  <td><input type="reset" value="  "></td>
  </tr>
 </table> 
 </form>
 
</center>
</body>
</html>
3. action.php

<?php
/**
 * Created by PhpStorm.
 * User: hyh
 * Date: 16-7-7
 * Time:   9:37
 */
//1.      
try{
 $pdo = new PDO("uri:mysqlPdo.ini","root","1");
}catch (PDOException $e) {
//  echo 'Connection failed: ' . $e->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 "<script>alter('    ');</script>";
 }else{
  echo "<script>alter('    ');</script>";
 }
 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 "<script>alter('    ');</script>";
 }else{
  echo "<script>alter('    ');</script>";
 }
 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 "<script>alter('    ');</script>";
 }else{
  echo "<script>alter('    ');</script>";
 }
 header('Location: index.php');
 break; 
 
 default:
 header('Location: index.php');
 break;
}
4.edit.php

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>      </title>
</head>
<body>
<center>
 <?php include ('menu.php');
 //1.      
 try{
 $pdo = new PDO("uri:mysqlPdo.ini","root","1");
 }catch (PDOException $e) {
 die('connection failed'.$e->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']}");
 }
 ?>
 
 <h3>      </h3>
 
 <form action="action.php?action=edit" method="post">
 <input type="hidden" name="id" value="<?php echo $stu['id'];?>">
 <table>
  <tr>
  <td>  </td>
  <td><input type="text" name="name" value="<?php echo $stu['name'];?>"></td>
  </tr>
  <tr>
  <td>  </td>
  <td><input type="text" name="age" value="<?php echo $stu['age'];?>"></td>
  </tr>
  <tr>
  <td>  </td>
  <td>
   <input type="radio" name="sex" value=" " <?php echo ($stu['sex'] == " ")? "checked":"";?> > 
  </td>
  <td>
   <input type="radio" name="sex" value=" " <?php echo ($stu['sex'] == " ")? "checked":"";?> > 
  </td>
  </tr>
  <tr>
  <td>  </td>
  <td><input type="text" name="classid" value="<?php echo $stu['classid']?>"></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td><input type="submit" value="  "></td>
  <td><input type="reset" value="  "></td>
  </tr>
 </table>
 </form>
 
 
</center>
 
<?php
?>
</body>
</html>
5. menu.php

<!DOCTYPE html>
<html lang="en">
<body>
 <h2>      </h2>
 <a href="index.php">     </a>
 <a href="add.php">     </a>
 <hr>
</body>
</html>
더 많은 학습 자 료 는 주제 인관리 시스템 개발에 주목 하 세 요.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기