javascript - 如何在考勤管理系统的数据库中保存在校生、缺勤学生名单?
问题描述
我想每天将学生的当前/缺席详细信息保存在数据库中。在我的项目中,我无法保存它。这个不知道怎么保存。我正在从另一个表(表名 - 学生)中获取学生姓名和卷号。帮我 。先感谢您
我的数据库表就像是,(表名 - 出勤)
+---+----------------+-------------+-----------------------------+
| | 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'>×</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>
这就是我保存出勤率的方式:
当我提交出勤率时,学生姓名和他们目前的缺勤名单应每天保存,并注明日期。
解决方案
我认为如果您纠正一些问题,您的解决方案应该可以工作:
改变
<form method="post" action="class_attendance .php" id="attendance_Form">
至
<form method="post" action="class_attendance.php" id="attendance_Form">
此外,$present_absent 尚未在表单的选择标记逻辑中定义,我建议添加一个占位符并从选项标记中删除 PHP 逻辑。
推荐阅读
- python-3.x - 如何使用 TensorFlow 训练两塔模型?
- algorithm - NIce Subsequence - 最长递增子序列的变体
- redux - 登录后不导航到经过身份验证的页面
- r - 通过列选择将数据帧拆分为多个数据帧
- c++ - 为什么这个合并排序实现不能正常工作?
- r - 选择嵌套列表的一个元素并将其转换为 R 中的数据框
- r - 需要用固定均值 25 和 st 2 替换年龄中的 NA
- reactjs - lit-element 和 React 的主要区别
- javascript - 无法加载通过 React App 中的父组件作为道具传递给子组件的图像
- mysql - 如何在 SQL 上创建显示订单行的新列