我想每天将学生的当前/缺席详细信息保存在数据库中。在我的项目中,我无法保存它。不知道如何保存。我从另一个表(表名-学生)获取学生的姓名和卷号。帮我 。预先谢谢
我的数据库表就像是(表名-出勤)
+---+----------------+-------------+-----------------------------+
| | 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>
这是我保存出席人数的方式:
我提交出勤时,应该每天保存学生姓名和他们的缺席列表。
答案 0 :(得分:0)
我认为,如果您纠正了一些问题,您的解决方案应该会起作用:
更改
<form method="post" action="class_attendance .php" id="attendance_Form">
到
<form method="post" action="class_attendance.php" id="attendance_Form">
此外,$ present_absent尚未在表单的选择标记逻辑中定义,我建议添加一个占位符并从选项标记中删除PHP逻辑。