检索数据并将其添加到数据库中


retrieve and add the data into database

我需要从数据库中检索相关数据,然后再次添加到考勤表中。 此代码显示许多错误。 实际上我不知道如何使用数组来添加数据。 谁能帮忙?? 谢谢ssssssss

<?php
    $sql = "select  p_module_ID, student_ID,
                    p_attendance_Date, p_attendance_Time, 
                    p_attendance_Status,p_attendance_reason
                    from attendance";
    $result = mysqli_query($con, $sql);
    if(!$result)
    {
        echo mysqli_error($con);
        exit();
    }
    while($rows = mysqli_fetch_array($result))
    {
        $attendance_list[] = array('p_module_ID' => $rows['p_module_ID'],
                                'student_ID' => $rows['student_ID'],
                                'p_attendance_Date' => $rows['p_attendance_Date'],
                                'p_attendance_Time' => $rows['p_attendance_Time'],
                                'p_attendance_Status' => $rows['p_attendance_Status'],
                                'p_attendance_reason' => $rows['p_attendance_reason']);
    }        
    ?>
    <html>
    <body>
    <form action="attendance.php" method="post" accept-charset='UTF-8'>
    <table border="0" cellspacing="20" >
    <tr>
        <td>
            <select name="p_module_ID">
                <?php
                $sql = "SELECT p_module_ID FROM schedule";
                $result = $con->query($sql);
                    while($row = mysqli_fetch_assoc($result)) {
                        echo "<option>".$row['p_module_ID']."</option>";
                    }
                ?>
            </select>
        </td>
    </tr>

    <tr>  
        <td>
            <select name="p_attendance_Date" >
            <?php
                $sql = "SELECT p_StartDate FROM schedule";
                $result = $con->query($sql);
                    while($row = mysqli_fetch_assoc($result)) {
                        echo "<option>".$row['p_StartDate']."</option>";
                    }
            ?>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <select name="p_attendance_Time">
            <?php
                $sql = "SELECT p_Time FROM schedule";
                $result = $con->query($sql);
                    while($row = mysqli_fetch_assoc($result)) {
                        echo "<option>".$row['p_Time']."</option>";
                    }
                ?>
            </select>
        </td>
    </tr>
    <table id="t01">
      <tr>
        <th> Student ID </th>
        <th> Name </th> 
        <th> Attendance </th>
        <th> Reason </th>
        <?php foreach($attendance_list as $attend) : ?>
            <tr>
                <td>
                    <?php
                    $sql = "SELECT p.student_ID,CONCAT(s.student_fname, ' ', s.student_lname) AS fullname FROM Pals p JOIN student s ON p.student_ID = s.student_ID WHERE student_role = 'Student' GROUP BY student_ID";
                    $result = $con->query($sql);
                    while($row = mysqli_fetch_assoc($result)) {
                    echo $attend[$row['student_id']];
                    }
                    ?>
                </td>
                <td>
                    <?php
                    $sql = "SELECT p.student_ID,CONCAT(s.student_fname, ' ', s.student_lname) AS Fullname FROM Pals p JOIN student s ON p.student_ID = s.student_ID WHERE student_role = 'Student' GROUP BY student_ID";
                    $result = $con->query($sql);
                    while($row = mysqli_fetch_assoc($result)) {
                    echo $attend['Fullname']; 
                    }
                    ?>
                </td>
                <td>
                    <?php echo $attend["p_attendance_Status"]; ?>
                </td>
                <td>
                    <?php echo $attend["p_attendance_reason"]; ?>
                </td>
            </tr>
      </tr>
            <?php endforeach; ?>
    </table>

    </table>
    </form>
    </body>
    </html>

使用 $row['student_Id'] 而不是 $row['student_id'] 。与Fullname相同。选择AS fullnameAS Fullname 。听听区分大小写。