学生已标记出勤一次,按下标记出勤按钮后无法再次标记

问题描述

我的目标:一旦按下按钮,就不能再次按下。它应该给出一个错误或某种消息,例如(第一次按下按钮以标记出勤,然后有人再次按下它)

" 出勤已被标记,您不能再次标记您的出勤 "

 {% form.non_field_errors %}
                        
    <form method="POST">
        {% csrf_token %}
        {{form.media}}
       
        {{form.as_p}}
        <button class="btn btn-info">Publish</button>
    </form>
    </div> 
 

解决方法

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

$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,'marked' ) ";
        $rs=mysqli_query($con,$query);

        if($rs){
            echo "Marked as Present";
        }
            

    }
    
}   

?>