bagaimana mengatasi codingan yang tidak bisa submit

<?php session_start(); include 'koneksi.php'; // Include your database connection

// Tampilkan error PHP ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

if (isset($_SESSION['sesi'])) { include 'header_guru.php';

// Process Attendance Form Submission
if ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot; &amp;&amp; isset($_POST[&#039;submit_absensi&#039;])) {
    $query = &quot;INSERT INTO absensi_7A (nama, kelas, tanggal, mapel, jam_pelajaran, keterangan, nama_guru) 
              VALUES (?, ?, ?, ?, ?, ?, ?)&quot;;
    $stmt = mysqli_prepare($conn, $query);
    
    if (!$stmt) {
        die(&#039;MySQL prepare error: &#039; . mysqli_error($conn));
    }

    foreach ($_POST[&#039;keterangan&#039;] as $nama =&gt; $keterangan) {
        $id_absen = $_POST[&#039;id_absen&#039;][$nama];
        $kelas = $_POST[&#039;kelas&#039;][$nama];
        $mapel = $_POST[&#039;mapel&#039;];
        $tanggal = $_POST[&#039;tanggal&#039;];
        $jam_pelajaran = $_POST[&#039;jam_pelajaran&#039;];
        $nama_guru = $_POST[&#039;nama_guru&#039;];

        $bind_result = mysqli_stmt_bind_param($stmt, &#039;sssssss&#039;, $nama, $kelas, $tanggal, $mapel, $jam_pelajaran, $keterangan, $nama_guru);
        if (!$bind_result) {
            die(&#039;Binding parameters failed: &#039; . mysqli_stmt_error($stmt));
        }

        if (!mysqli_stmt_execute($stmt)) {
            echo &quot;&lt;script&gt;alert(&#039;Gagal menambahkan data absensi: &quot; . mysqli_stmt_error($stmt) . &quot;&#039;);&lt;/script&gt;&quot;;
        }
    }
    mysqli_stmt_close($stmt);
    echo &quot;&lt;script&gt;alert(&#039;Data absensi berhasil ditambahkan&#039;);&lt;/script&gt;&quot;;
}

// Fetch Data Guru, Mapel, dan Siswa
$query_guru = &quot;SELECT DISTINCT nama_guru FROM guru&quot;;
$result_guru = mysqli_query($conn, $query_guru);
$teachers = mysqli_fetch_all($result_guru, MYSQLI_ASSOC);

$query_mapel = &quot;SELECT id_mapel, nama_mapel FROM mapel&quot;;
$result_mapel = mysqli_query($conn, $query_mapel);
$subjects = mysqli_fetch_all($result_mapel, MYSQLI_ASSOC);

$query_students = &quot;SELECT id_siswa, nama FROM siswa WHERE kelas = &#039;7A&#039;&quot;;
$result_students = mysqli_query($conn, $query_students);
$students = mysqli_fetch_all($result_students, MYSQLI_ASSOC);

?> <!DOCTYPE html> <html lang="id"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Absensi Siswa 7A</title> <link rel="stylesheet" href="styles/bootstrap/css/bootstrap.min.css"> </head> <body> <div class="container-fluid mt-4"> <div class="row"> <!-- Sidebar --> <div class="col-md-3"> <?php include 'sidebar.php'; ?> </div>

    &lt;!-- Main Content --&gt;
    &lt;div class=&quot;col-md-9&quot;&gt;
        &lt;!-- Form Absensi --&gt;
        &lt;h2 class=&quot;text-secondary mt-4&quot;&gt;Form Absensi 7A&lt;/h2&gt;
        &lt;hr&gt;
        &lt;form action=&quot;&quot; method=&quot;POST&quot;&gt;
            &lt;!-- Subject --&gt;
            &lt;div class=&quot;form-group mb-3&quot;&gt;
                &lt;label for=&quot;mapel&quot;&gt;Mata Pelajaran&lt;/label&gt;
                &lt;select class=&quot;form-control&quot; id=&quot;mapel&quot; name=&quot;mapel&quot; required&gt;
                    &lt;?php foreach ($subjects as $subject): ?&gt;
                        &lt;option value=&quot;&lt;?php echo htmlspecialchars($subject[&#039;nama_mapel&#039;]); ?&gt;&quot;&gt;&lt;?php echo htmlspecialchars($subject[&#039;nama_mapel&#039;]); ?&gt;&lt;/option&gt;
                    &lt;?php endforeach; ?&gt;
                &lt;/select&gt;
            &lt;/div&gt;

            &lt;!-- Jam Pelajaran, Nama Guru, Tanggal --&gt;
            &lt;div class=&quot;form-group mb-3&quot;&gt;
                &lt;label for=&quot;jam_pelajaran&quot;&gt;Jam Pelajaran&lt;/label&gt;
                &lt;input type=&quot;time&quot; class=&quot;form-control&quot; id=&quot;jam_pelajaran&quot; name=&quot;jam_pelajaran&quot; required&gt;
            &lt;/div&gt;
            &lt;div class=&quot;form-group mb-3&quot;&gt;
                &lt;label for=&quot;nama_guru&quot;&gt;Nama Guru&lt;/label&gt;
                &lt;select class=&quot;form-control&quot; id=&quot;nama_guru&quot; name=&quot;nama_guru&quot; required&gt;
                    &lt;?php foreach ($teachers as $teacher): ?&gt;
                        &lt;option value=&quot;&lt;?php echo htmlspecialchars($teacher[&#039;nama_guru&#039;]); ?&gt;&quot;&gt;&lt;?php echo htmlspecialchars($teacher[&#039;nama_guru&#039;]); ?&gt;&lt;/option&gt;
                    &lt;?php endforeach; ?&gt;
                &lt;/select&gt;
            &lt;/div&gt;
            &lt;div class=&quot;form-group mb-3&quot;&gt;
                &lt;label for=&quot;tanggal&quot;&gt;Tanggal&lt;/label&gt;
                &lt;input type=&quot;date&quot; class=&quot;form-control&quot; id=&quot;tanggal&quot; name=&quot;tanggal&quot; value=&quot;&lt;?php echo date(&#039;Y-m-d&#039;); ?&gt;&quot; required&gt;
            &lt;/div&gt;

            &lt;!-- Attendance Table --&gt;
            &lt;table class=&quot;table table-bordered&quot;&gt;
                &lt;thead&gt;
                    &lt;tr&gt;
                        &lt;th&gt;ID Absen&lt;/th&gt;
                        &lt;th&gt;Nama&lt;/th&gt;
                        &lt;th&gt;Hadir&lt;/th&gt;
                        &lt;th&gt;Izin&lt;/th&gt;
                        &lt;th&gt;Alpa&lt;/th&gt;
                        &lt;th&gt;Sakit&lt;/th&gt;
                    &lt;/tr&gt;
                &lt;/thead&gt;
                &lt;tbody&gt;
                    &lt;?php foreach ($students as $student): ?&gt;
                        &lt;tr&gt;
                            &lt;td&gt;
                                &lt;?php echo htmlspecialchars($student[&#039;id_siswa&#039;]); ?&gt;
                                &lt;input type=&quot;hidden&quot; name=&quot;id_absen[&lt;?php echo htmlspecialchars($student[&#039;nama&#039;]); ?&gt;]&quot; value=&quot;&lt;?php echo htmlspecialchars($student[&#039;id_siswa&#039;]); ?&gt;&quot;&gt;
                                &lt;input type=&quot;hidden&quot; name=&quot;kelas[&lt;?php echo htmlspecialchars($student[&#039;nama&#039;]); ?&gt;]&quot; value=&quot;7A&quot;&gt;
                            &lt;/td&gt;
                            &lt;td&gt;&lt;?php echo htmlspecialchars($student[&#039;nama&#039;]); ?&gt;&lt;/td&gt;
                            &lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;keterangan[&lt;?php echo htmlspecialchars($student[&#039;nama&#039;]); ?&gt;]&quot; value=&quot;Hadir&quot; required&gt;&lt;/td&gt;
                            &lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;keterangan[&lt;?php echo htmlspecialchars($student[&#039;nama&#039;]); ?&gt;]&quot; value=&quot;Izin&quot; required&gt;&lt;/td&gt;
                            &lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;keterangan[&lt;?php echo htmlspecialchars($student[&#039;nama&#039;]); ?&gt;]&quot; value=&quot;Alpa&quot; required&gt;&lt;/td&gt;
                            &lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;keterangan[&lt;?php echo htmlspecialchars($student[&#039;nama&#039;]); ?&gt;]&quot; value=&quot;Sakit&quot; required&gt;&lt;/td&gt;
                        &lt;/tr&gt;
                    &lt;?php endforeach; ?&gt;
                &lt;/tbody&gt;
            &lt;/table&gt;

            &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; name=&quot;submit_absensi&quot;&gt;Submit Absensi&lt;/button&gt;
        &lt;/form&gt;

    &lt;/div&gt;
&lt;/div

<?php include 'footer.php'; } else { echo "<script> alert('Silahkan Login Terlebih Dahulu!'); window.location = 'absensi_user_kelas7a.php'; </script>"; } ?>

avatar sitinurulkhabibah
@sitinurulkhabibah

1 Kontribusi 0 Poin

Diperbarui 3 bulan yang lalu

1 Jawaban:

wah,,, banyak banget yang bisa menyebabkan ga bisa submit,,, coba 1 per 1 kah ? ?

  1. Pastikan file 'koneksi.php' sudah benar dan koneksi ke database berhasil.
  2. coba tampilin error supaya mudah debugging nya (itu di bagian atas dah ada ini_set,, tapi di // bisa di coba buat cek errornya apa)
  3. Cek nilai POST,, bisa pake var_dump($_POST);
  4. cek tabel dengan insertnya apa sudah betul (bisa kelebihan row, ato beda format,, misal input date pake varchar)

di coba dulu 4 hal ini,,,

avatar yukaristel
@yukaristel

36 Kontribusi 32 Poin

Dipost 3 bulan yang lalu

Login untuk ikut Jawaban