Postingan lainnya
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["REQUEST_METHOD"] == "POST" && isset($_POST['submit_absensi'])) {
$query = "INSERT INTO absensi_7A (nama, kelas, tanggal, mapel, jam_pelajaran, keterangan, nama_guru)
VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($conn, $query);
if (!$stmt) {
die('MySQL prepare error: ' . mysqli_error($conn));
}
foreach ($_POST['keterangan'] as $nama => $keterangan) {
$id_absen = $_POST['id_absen'][$nama];
$kelas = $_POST['kelas'][$nama];
$mapel = $_POST['mapel'];
$tanggal = $_POST['tanggal'];
$jam_pelajaran = $_POST['jam_pelajaran'];
$nama_guru = $_POST['nama_guru'];
$bind_result = mysqli_stmt_bind_param($stmt, 'sssssss', $nama, $kelas, $tanggal, $mapel, $jam_pelajaran, $keterangan, $nama_guru);
if (!$bind_result) {
die('Binding parameters failed: ' . mysqli_stmt_error($stmt));
}
if (!mysqli_stmt_execute($stmt)) {
echo "<script>alert('Gagal menambahkan data absensi: " . mysqli_stmt_error($stmt) . "');</script>";
}
}
mysqli_stmt_close($stmt);
echo "<script>alert('Data absensi berhasil ditambahkan');</script>";
}
// Fetch Data Guru, Mapel, dan Siswa
$query_guru = "SELECT DISTINCT nama_guru FROM guru";
$result_guru = mysqli_query($conn, $query_guru);
$teachers = mysqli_fetch_all($result_guru, MYSQLI_ASSOC);
$query_mapel = "SELECT id_mapel, nama_mapel FROM mapel";
$result_mapel = mysqli_query($conn, $query_mapel);
$subjects = mysqli_fetch_all($result_mapel, MYSQLI_ASSOC);
$query_students = "SELECT id_siswa, nama FROM siswa WHERE kelas = '7A'";
$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>
<!-- Main Content -->
<div class="col-md-9">
<!-- Form Absensi -->
<h2 class="text-secondary mt-4">Form Absensi 7A</h2>
<hr>
<form action="" method="POST">
<!-- Subject -->
<div class="form-group mb-3">
<label for="mapel">Mata Pelajaran</label>
<select class="form-control" id="mapel" name="mapel" required>
<?php foreach ($subjects as $subject): ?>
<option value="<?php echo htmlspecialchars($subject['nama_mapel']); ?>"><?php echo htmlspecialchars($subject['nama_mapel']); ?></option>
<?php endforeach; ?>
</select>
</div>
<!-- Jam Pelajaran, Nama Guru, Tanggal -->
<div class="form-group mb-3">
<label for="jam_pelajaran">Jam Pelajaran</label>
<input type="time" class="form-control" id="jam_pelajaran" name="jam_pelajaran" required>
</div>
<div class="form-group mb-3">
<label for="nama_guru">Nama Guru</label>
<select class="form-control" id="nama_guru" name="nama_guru" required>
<?php foreach ($teachers as $teacher): ?>
<option value="<?php echo htmlspecialchars($teacher['nama_guru']); ?>"><?php echo htmlspecialchars($teacher['nama_guru']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group mb-3">
<label for="tanggal">Tanggal</label>
<input type="date" class="form-control" id="tanggal" name="tanggal" value="<?php echo date('Y-m-d'); ?>" required>
</div>
<!-- Attendance Table -->
<table class="table table-bordered">
<thead>
<tr>
<th>ID Absen</th>
<th>Nama</th>
<th>Hadir</th>
<th>Izin</th>
<th>Alpa</th>
<th>Sakit</th>
</tr>
</thead>
<tbody>
<?php foreach ($students as $student): ?>
<tr>
<td>
<?php echo htmlspecialchars($student['id_siswa']); ?>
<input type="hidden" name="id_absen[<?php echo htmlspecialchars($student['nama']); ?>]" value="<?php echo htmlspecialchars($student['id_siswa']); ?>">
<input type="hidden" name="kelas[<?php echo htmlspecialchars($student['nama']); ?>]" value="7A">
</td>
<td><?php echo htmlspecialchars($student['nama']); ?></td>
<td><input type="radio" name="keterangan[<?php echo htmlspecialchars($student['nama']); ?>]" value="Hadir" required></td>
<td><input type="radio" name="keterangan[<?php echo htmlspecialchars($student['nama']); ?>]" value="Izin" required></td>
<td><input type="radio" name="keterangan[<?php echo htmlspecialchars($student['nama']); ?>]" value="Alpa" required></td>
<td><input type="radio" name="keterangan[<?php echo htmlspecialchars($student['nama']); ?>]" value="Sakit" required></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<button type="submit" class="btn btn-primary" name="submit_absensi">Submit Absensi</button>
</form>
</div>
</div
<?php include 'footer.php'; } else { echo "<script> alert('Silahkan Login Terlebih Dahulu!'); window.location = 'absensi_user_kelas7a.php'; </script>"; } ?>
1 Jawaban:
wah,,, banyak banget yang bisa menyebabkan ga bisa submit,,, coba 1 per 1 kah ? ?
- Pastikan file 'koneksi.php' sudah benar dan koneksi ke database berhasil.
- coba tampilin error supaya mudah debugging nya (itu di bagian atas dah ada ini_set,, tapi di // bisa di coba buat cek errornya apa)
- Cek nilai POST,, bisa pake var_dump($_POST);
- cek tabel dengan insertnya apa sudah betul (bisa kelebihan row, ato beda format,, misal input date pake varchar)
di coba dulu 4 hal ini,,,