学生在按下标记出勤按钮时无法再次标记

  • 本文关键字:按钮 下标 php validation button
  • 更新时间 :
  • 英文 :


我的目标:一旦按下按钮,就无法再按下。它应该给出一个错误或类似于的消息(当第一次按下按钮来标记出勤率时,有人再次按下它(

"考勤已经标记,您不能再标记您的考勤";

<?php 
session_start();
?>
<form method="post">
<button name="attendence" >mark attendence  </button>
</form>

<?php
if (isset($_POST['attendence'])){
$id =$_SESSION["id"];
$con = mysqli_connect('localhost','root','','yo');
$query = "INSERT INTO attendance (present,absent, datetime, std_id) VALUES ('present','',current_timestamp(), $id ) ";
$rs=mysqli_query($con,$query);
if($rs){
echo "Marked as Present";
}
else {
echo "marked as Absent";
}

}

如果学生已经被以下代码标记为存在,则必须在数据库中搜索:

$id =$_SESSION["id"];
$query = "SELECT * FROM attendance WHERE std_id = '$id' ) ";
$result=mysqli_query($con,$query);
while ($row = mysqli_fetch_assoc($result)) { 
if ($row['present'] == 'present') {
echo' Student already marked as present';
}
else {
echo'
<form method="post">
<button name="attendence" >mark attendence  </button>
</form>';
}
}

first:在数据库中搜索学生是否已经被标记/在场。如果他/她在场;写点什么";。

然后:插入查询以标记当前

<?php
if (isset($_POST['attendence'])){
$id =$_SESSION["id"];
$con = mysqli_connect('localhost','root','','yo');

$mark_query = "SELECT * FROM `attendance` WHERE date=CURRENT_DATE and std_id=$id ";
$result = mysqli_query($con, $mark_query);
$row = mysqli_fetch_assoc($result);

if ($row['present']=='present') {
echo "Student already marked ".$row['present'];
}

else{
$query = "INSERT INTO attendance (present,absent, datetime, std_id,date,marked_status) VALUES ('present','',current_timestamp(), $id, current_timestamp(),'marked' ) ";
$rs=mysqli_query($con,$query);
if($rs){
echo "Marked as Present";
}

}

}   
?>

相关内容

  • 没有找到相关文章

最新更新