首页 > 解决方案 > 如何在考勤管理系统的数据库中保存在校生、缺勤学生名单?

问题描述

我想每天将学生的当前/缺席详细信息保存在数据库中。在我的项目中,我无法保存它。这个不知道怎么保存。我正在从另一个表(表名 - 学生)中获取学生姓名和卷号。帮我 。先感谢您

我的数据库表就像是,(表名 - 出勤)

+---+----------------+-------------+-----------------------------+
|   |      Name      |    Type     |         Attributes          |
+---+----------------+-------------+-----------------------------+
| 1 | id Primary     | int(50)     | No                          |
| 2 | name           | varchar(20) | No                          |
| 3 | Roll_Number    | varchar(20) | No                          |
| 4 | date           | timestamp   | on update CURRENT_TIMESTAMP |
| 5 | present_absent | varchar(20) | No                          |
+---+----------------+-------------+-----------------------------+

我的代码是 class_attendance。php在下面

<?php
     include("php/connect.php");
     include("php/check.php");

 $res['role']=$_SESSION['role'];

 $hid = $_SESSION['id'];

 $errormsg = '';
 $action = "add";

  $name ='';
  $Roll_Number =''; 
  $present_absent =''; 

 if(isset($_POST['save']))
     {
 $id = mysqli_real_escape_string($conn,$_POST['id']);
 $sql = "select name,Roll_Number from student  ";


  $sql = $conn->query("INSERT INTO attendance (name,Roll_Number,present_absent)
  VALUES ('$name','$Roll_Number','$present_absent')") ;

    echo '<script type="text/javascript">window.location="attendance.php";</script>';

 }



 $action = "add";
     if(isset($_GET['action']) && $_GET['action']=="edit" )
 {
   $id = isset($_GET['id'])?mysqli_real_escape_string($conn,$_GET['id']):'';

  $sqlEdit = $conn->query("SELECT * FROM attendance WHERE id='".$id."'");
 if($sqlEdit->num_rows)
  {
   $rowsEdit = $sqlEdit->fetch_assoc();
  extract($rowsEdit);
   $action = "update";
 }
 else
  {
    $_GET['action']="";
  }

}


  if(isset($_REQUEST['act']) && @$_REQUEST['act']=="1")
 {
  $errormsg = "<div class='alert alert-success'> <a href='#' class='close' 
  data-dismiss='alert' aria-label='close'>&times;</a>
  <strong>Success!</strong> Student Add successfully</div>";
 }

?>




<div class="panel panel-default">
    <div class="panel-heading">
            Manage Student  
   <? php echo "Today is " . date("m/d/Y") . "";?>
    </div>
<div class="panel-body">
 <div class="table-sorting table-responsive">
  <table class="table table-striped table-bordered table-hover id="Sortable">
         <thead>
               <tr>
                   <th>S.No</th>
                   <th>Roll Number</th>
                   <th>Name</th>
                   <th>Attendance</th>
                </tr>
           </thead>
         <tbody>

<form method="post" action="class_attendance .php" id="attendance_Form">
            <?php if(isset($_GET["id"]))  
 { 
    $sql = "SELECT * FROM student as s,branch as b WHERE s.branch=b.id and b.id='".$_GET['id']."' and s.delete_status='0' " ;
        $q = $conn->query($sql);
        $i=1;
        while($r = $q->fetch_assoc())
            {

            echo '<tr >
                     <td>'.$i.'</td>
                     <td>'.$r['Roll_Number'].'</td>
                     <td>'.$r['name'].'</td>
                     <td> 
<select  class="form-control" id="present_absent" name="present_absent">                      
       <option  if ($present_absent == "Present" ) echo "selected" value="Present">Present</option>
       <option  if ($present_absent == "Absent" ) echo "selected"  value="Absent">Absent</option>

                      </select>
                     </td>
                   </tr>';
                $i++;
                        }
 }

                     echo "</table>";
                            ?>
                     <button type="submit" name="save" >Save </button>
            </form>
          </tbody>
        </table>
      </div>
    </div>
 </div>

这就是我保存出勤率的方式:这就是我保存出勤率的方法

当我提交出勤率时,学生姓名和他们目前的缺勤名单应每天保存,并注明日期。

标签: javascriptphphtmlmysql

解决方案


我认为如果您纠正一些问题,您的解决方案应该可以工作:

改变

<form method="post" action="class_attendance .php" id="attendance_Form">

<form method="post" action="class_attendance.php" id="attendance_Form">

此外,$present_absent 尚未在表单的选择标记逻辑中定义,我建议添加一个占位符并从选项标记中删除 PHP 逻辑。


推荐阅读