Javascript 如何在考勤管理系统的数据库中保存当前缺勤学生名单?
我想每天在数据库中保存学生当前/缺席的详细信息。在我的项目中,我无法保存它。我不知道如何保存这个。我从另一个表名-学生处获取学生姓名和卷号。帮助我。先谢谢你 我的数据库表类似于is,表名-考勤Javascript 如何在考勤管理系统的数据库中保存当前缺勤学生名单?,javascript,php,html,mysql,Javascript,Php,Html,Mysql,我想每天在数据库中保存学生当前/缺席的详细信息。在我的项目中,我无法保存它。我不知道如何保存这个。我从另一个表名-学生处获取学生姓名和卷号。帮助我。先谢谢你 我的数据库表类似于is,表名-考勤 +---+----------------+-------------+-----------------------------+ | | Name | Type | Attributes | +---+--------------
+---+----------------+-------------+-----------------------------+
| | 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 |
+---+----------------+-------------+-----------------------------+
我的代码是课堂出勤。下面是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">
到
另外,表单中的select标记逻辑中尚未定义$present\u缺席,我建议添加一个占位符,并从选项标记中删除PHP逻辑。您的数据库设计存在很多问题。首先:名字-如果你有多个弗雷德·史密斯注册。系统将选择哪一个?最好让外键指向学生ID或其他学生的单号。第二,当前缺少的字段只需要是char1。这将允许您为出勤/不出勤设置特定代码。在创建/搜索信息时使生活更轻松。第三,你的id也应该是自动递增的。这段代码有点乱七八糟,我真的搞不清楚到底发生了什么。设置$add两次,将$sql分配给select语句,然后立即将其覆盖到查询对象。我不知道你为什么要回显javascript重定向?您也在直接传递变量,因此您面临着SQL注入的巨大风险,但我也看不出这些$name=$卷数=$现在缺席=;准备好了吗?我认为第一步应该是重新组织你的编码,你能解释一下为什么你不能在你的系统中保存这些数据吗?除了HTML和PHP之间的混淆之外,所有这些代码的确切问题是什么?您应该避免这些混淆,因为这些包含的部分看起来不正确includehp/connect.PHP;includehp/check.php;
<form method="post" action="class_attendance.php" id="attendance_Form">