Script Aplikasi Ujian Online PHP. Ini adalah script php yang digunakan untuk tes atau ujian online di sekolah atau lembaga pendidikan misalkan saja kursus. Saya mengembangkan aplikasi ujian online untuk penerimaan siswa baru, karyawan baru, dan juga ujian peserta kursus. Cara membuat web ujian online menggunakan pemrograman php. Dan untuk databaseya menggunakan mysql.
Script Aplikasi Ujian Online PHP
Beberapa contoh penggunaan script ujian online secara umum, pada berbagai bidang yang ada:
- Penerimaan siswa baru (PSB)
- Penerimaan mahasiswa baru (PMB)
- Ujian online Seleksi Karyawan
- Ujian online kursus komputer
- Ujian online kursus bahasa inggris
- Ujian online kursus matematika
- Ujian online pelatihan pertanian
- Ujian online guru bidang studi
- Ujian online mata kuliah
- Tes psikologi online
Script php ujian online
Untuk membutnya saya menggunakan 3 tabel database yaitu tabel soal, tabel dan jawaban, dan tabel user.
Untuk tampilannya sebagai berikut:
Script php
1. tes.php
<?php include "config/fungsi.php"; switch ($_GET['aksi']){ default; //cek token $token= "SELECT token FROM soal_tes ORDER BY no_soal DESC LIMIT 1"; $prosestoken = mysql_query($token); $datatoken = mysql_fetch_array($prosestoken); //cek kd_karyawan $sqlkd = "SELECT * FROM karyawan WHERE nm_karyawan = '$_SESSION[nm_karyawan]'"; $kd_karyawan = mysql_fetch_array(mysql_query($sqlkd)); //cek jawaban $jwb = "SELECT * FROM jawaban_tes WHERE kd_karyawan ='$kd_karyawan[kd_karyawan]' AND token = '$datatoken[token]'"; $xjwb = mysql_query($jwb); if($data=mysql_num_rows($xjwb) == 100){ echo '<table class="full"> <tr> <th>Soal tes selesai di Jawab</th> </tr> <tr>'; //jml soal $totalsoal = mysql_num_rows(mysql_query("SELECT * FROM soal_tes")); //hasil jawaban $tampil = "SELECT a. * , b. * FROM soal_tes a, jawaban_tes b WHERE a.pilihan_benar = b.jawaban AND a.no_soal = b.no_soal AND a.token = b.token AND b.kd_karyawan = '$kd_karyawan[kd_karyawan]'"; $sql = mysql_query($tampil); $jbenar = mysql_num_rows($sql); $jsalah = $totalsoal-$jbenar; $skor = $jbenar/10; echo ' <tr> <td colspan=2 align=center> Jawaban benar: '.$jbenar.'<br/> Jawaban salah: '.$jsalah.'<br/> Score Anda: '.$skor.' </td></tr></table>'; }else{ echo '<h3>Salamat datang di tes online</h3> <p align=center>Harap mengerjakan soal dengan teliti, baca soal dan pilihlah jawaban yang paling benar. Untuk megerjakan soal tes silahkan klik lanjut </p><p align=center><a href="?modul=tes&aksi=tampil&token='.$datatoken[token].'" class="tombol">Lanjut</a></p>'; } break; # Menampilkan data case "tampil"; echo '<script> function validateForm() { var a = document.forms["myForm"]["jawaban"].value; if (a==null || a=="") { alert("Pertayaan harus dijawab"); return false; } } </script>'; //cek no soal $sqlkd = "SELECT * FROM karyawan WHERE nm_karyawan = '$_SESSION[nm_karyawan]'"; $kd = mysql_fetch_array(mysql_query($sqlkd)); $no = mysql_query("SELECT * FROM jawaban_tes WHERE kd_karyawan='$kd[kd_karyawan]' ORDER BY no_soal DESC "); $nosoal = mysql_fetch_array($no); if($nosoalxx = mysql_num_rows($no) < 1 ){ $nosoalx = 1; }else{ $nosoalx= $nosoal[no_soal]+1; } $totalsoal = mysql_num_rows(mysql_query("SELECT * FROM soal_tes")); if($nosoalx<=100){ echo ' <h3>Soal no '.$nosoalx.' dari '.$totalsoal.' Soal</h3> '; echo '<form action="modul/tes/aksi_tes.php?aksi=insert" method="POST" name="myForm" onsubmit="return validateForm()"> <table class="full"> <tr> <th>Soal Tes</th> </tr> <tr>'; $i=0; $tampil = "SELECT * FROM soal_tes WHERE token='$_GET[token]' AND no_soal='$nosoalx' ORDER BY no_soal ASC LIMIT 1"; $sql = mysql_query($tampil); while($data = mysql_fetch_array($sql)) { $i++; echo " <td><p style='margin:0 0 10px 5px;font-size:18px;'>$data[soal] ?</p>"; echo '<input type="radio" name="jawaban" value="a">a. '.$data[pilihan_a].'<br/>'; echo '<input type="radio" name="jawaban" value="b">b. '.$data[pilihan_b].'<br/>'; echo '<input type="radio" name="jawaban" value="c">c. '.$data[pilihan_c].'<br/>'; echo '<input type="radio" name="jawaban" value="d">d. '.$data[pilihan_d].'<br/>'; echo '<input type="radio" name="jawaban" value="e">e. '.$data[pilihan_e].'<br/>'; echo " <input type=hidden name=token value=".$data[token]."> <input type=hidden name=no_soal value=".$nosoalx."> <input type=hidden name=kd_karyawan value=".$kd[kd_karyawan]."> </tr>"; } echo ' <tr> <td colspan=2 align=center> <input type=submit value=Jawab class="tombol"> </td></tr></table></form>'; }else{ echo '<table class="full"> <tr> <th>Soal tes selesai di Jawab</th> </tr> <tr>'; $i=0; $tampil = "SELECT a. * , b. * FROM soal_tes a, jawaban_tes b WHERE a.pilihan_benar = b.jawaban AND a.no_soal = b.no_soal AND a.token = b.token AND b.kd_karyawan = '$kd[kd_karyawan]'"; $sql = mysql_query($tampil); $jbenar = mysql_num_rows($sql); $jsalah = $totalsoal-$jbenar; $skor = $jbenar/10; echo ' <tr> <td colspan=2 align=center> Jawaban benar: '.$jbenar.'<br/> Jawaban salah: '.$jsalah.'<br/> Score Anda: '.$skor.' </td></tr></table>'; } break; case "admin": echo ' <h3>Penilaian Tes Online</h3> <table class="full"> <tr> <th>No</th> <th>Karyawan</th> <th>Jawaban Benar</th> <th>Nilai Asli</th> <th>Nilai Input</th> </tr> <tr>'; $i=0; $tampil = "SELECT * FROM karyawan"; $sql = mysql_query($tampil); while($data = mysql_fetch_array($sql)) { $i++; $tampil2 = "SELECT a. * , b. * FROM soal_tes a, jawaban_tes b WHERE a.pilihan_benar = b.jawaban AND a.no_soal = b.no_soal AND a.token = b.token AND b.kd_karyawan = '$data[kd_karyawan]'"; $sql2 = mysql_query($tampil2); $jbenar = mysql_num_rows($sql2); $jsalah = $totalsoal-$jbenar; $skor = $jbenar/10; echo " <td>$i</td> <td>$data[nm_karyawan]</td>"; if($skor < 1 && $jbenar < 1){ $skor = ''; $jbenar = ''; } echo "<td>$jbenar</td> <td align=center>$skor</td>"; echo "<td align=center>".sederhana($skor)."</td> </tr>"; } echo '</table>'; break; } ?>
2. aksi_tes.php
<?php include "../../config/koneksi.php"; $kd_karyawan = $_POST['kd_karyawan']; $jawaban = $_POST['jawaban']; $no_soal = $_POST['no_soal']; $token = $_POST['token']; switch ($_GET['aksi']) { # Insert data case "insert" : $sql = "INSERT INTO jawaban_tes(kd_karyawan,jawaban,no_soal,token) values('$kd_karyawan','$jawaban','$no_soal','$token')"; //echo "$sql";exit; $hasil = mysql_query($sql); if($hasil){ //pesan data berhasil disimpan echo " <script> window.location=\"../../?modul=tes&aksi=tampil&token=$token\"; </script>"; } break; # Update data case "update" : $update = "UPDATE soal_tes SET soal = '$soal',pilihan_benar = '$pilihan_benar' ,pilihan_a = '$pilihan_a' ,pilihan_b = '$pilihan_b' ,pilihan_c = '$pilihan_c' ,pilihan_d = '$pilihan_d' ,pilihan_e = '$pilihan_e' WHERE id_soal='$id_soal'"; //echo "$update";exit; $hasil = mysql_query($update); if($update){ echo " <script> window.location=\"../../?modul=soal&aksi=tampil\"; </script>"; } break; # Delete data case "delete" : $delete="DELETE FROM soal_tes WHERE id_soal ='$_GET[id]'"; //echo $delete;exit; $hasil=mysql_query($delete); if($hasil){ echo " <script> window.location=\"../../?modul=soal&aksi=tampil\"; </script>"; } break; } ?>
3. soal.php
<?php switch ($_GET['aksi']){ # Tambah data case "tambah": echo ' <script> function validateForm() { var a = document.forms["myForm"]["kd_kriteria"].value; var b = document.forms["myForm"]["nm_kriteria"].value; if (a==null || a=="" || b==null || b=="") { alert("Tidak boleh kosong"); return false; } } </script> <h3>Tambah Data Soal Tes </h3> <form method="post" action="modul/soal/aksi_soal.php?aksi=insert" name="myForm" onsubmit="return validateForm()"> <table> <tr> <td>Soal</td> <td><input name="soal" type="text" size="30"></td> </tr> <tr> <td>Jawaban Benar</td> <td> <input type="radio" name="pilihan_benar" value="a">a <input type="radio" name="pilihan_benar" value="b">b <input type="radio" name="pilihan_benar" value="c">c <input type="radio" name="pilihan_benar" value="d">d <input type="radio" name="pilihan_benar" value="e">e </td> </tr> <tr> <td>Pilihan a</td> <td><input name="pilihan_a" type="text" size="20"></td> </tr> <tr> <td>Pilihan b</td> <td><input name="pilihan_b" type="text" size="20"></td> </tr> <tr> <td>Pilihan c</td> <td><input name="pilihan_c" type="text" size="20"></td> </tr> <tr> <td>Pilihan d</td> <td><input name="pilihan_d" type="text" size="20"></td> </tr> <tr> <td>Pilihan e</td> <td><input name="pilihan_e" type="text" size="20"> <input name="token" type="hidden""> </td> </tr> <tr> <td colspan="2">'; #cek token $token= "SELECT * FROM soal_tes ORDER BY no_soal DESC LIMIT 1"; $prosestoken = mysql_query($token); $datatoken = mysql_fetch_array($prosestoken); if($deteksitoken = mysql_num_rows($prosestoken) < 1 ){ $isitoken = date('Y-m-d:H:i:s'); $no_soal = 1; }else{ $isitoken = $datatoken[token]; $no_soal = $datatoken[no_soal]+1; } echo '<input type=hidden name=token value="'.$isitoken.'"> <input type=hidden name=no_soal value="'.$no_soal.'"> <input type="submit" value="Simpan" class="tombol"/> <input type="reset" name="reset" value="Batal" class="tombol" onclick=self.history.back()></td> </tr> </table> </form>'; break; # Edit data case "edit": $edit = "SELECT * FROM soal_tes WHERE no_soal = '$_GET[id]'"; $hasil = mysql_query($edit); $data = mysql_fetch_array($hasil); echo ' <script> function validateForm() { var a = document.forms["myForm"]["kd_kriteria"].value; var b = document.forms["myForm"]["nm_kriteria"].value; if (a==null || a=="" || b==null || b=="") { alert("Tidak boleh kosong"); return false; } } </script> <h3>Form Edit Data Master Soal Tes</h3> <form method="post" action="modul/soal/aksi_soal.php?aksi=update&id='.$_GET[id].'" name="myForm" onsubmit="return validateForm()"> <table> <tr> <td>Soal</td> <td><input name="soal" value="'.$data[soal].'" type="text" size="30"></td> </tr> <tr> <td>Jawaban Benar</td> <td> <input type="radio" name="pilihan_benar" value="a"';if($data[pilihan_benar]=='a'){echo "checked";} echo '>a <input type="radio" name="pilihan_benar" value="b"';if($data[pilihan_benar]=='b'){echo "checked";} echo '>b <input type="radio" name="pilihan_benar" value="c"';if($data[pilihan_benar]=='c'){echo "checked";} echo '>c <input type="radio" name="pilihan_benar" value="d"';if($data[pilihan_benar]=='d'){echo "checked";} echo '>d <input type="radio" name="pilihan_benar" value="e"';if($data[pilihan_benar]=='e'){echo "checked";} echo '>e </td> </tr> <tr> <td>Pilihan a</td> <td><input name="pilihan_a" value="'.$data[pilihan_a].'" type="text" size="20"></td> </tr> <tr> <td>Pilihan b</td> <td><input name="pilihan_b" value="'.$data[pilihan_b].'" type="text" size="20"></td> </tr> <tr> <td>Pilihan c</td> <td><input name="pilihan_c" value="'.$data[pilihan_c].'" type="text" size="20"></td> </tr> <tr> <td>Pilihan d</td> <td><input name="pilihan_d" value="'.$data[pilihan_d].'" type="text" size="20"></td> </tr> <tr> <td>Pilihan e</td> <td><input name="pilihan_e" value="'.$data[pilihan_e].'" type="text" size="20"> <input name="no_soal" value="'.$_GET[id].'" type="hidden">'; echo '<input type=hidden name=token value="'.$data[token].'"> </td> </tr> <tr> <td colspan="2"> <input type="submit" value="Simpan" class="tombol"/> <input type="reset" name="reset" value="Batal" class="tombol" onclick=self.history.back()></td> </tr> </table> </form>'; break; # Menampilkan data case "tampil"; echo ' <h3>Data Master Soal Tes</h3> <a href="?modul=soal&aksi=tambah" class="tombol">Tambah</a> <table class="full"> <tr> <th>No</th> <th>Soal Tes</th> <th>Pilihan Benar</th> <th>Detail</th> <th>Edit</th> <th>Hapus</th> </tr> <tr>'; $i=0; $tampil = "SELECT * FROM soal_tes"; $sql = mysql_query($tampil); while($data = mysql_fetch_array($sql)) { $i++; //konfirmasi hapus echo " <script language=\"JavaScript\"> function konfirmasi() { tanya = confirm('Anda Yakin Akan Menghapus Data ?'); if (tanya == true) return true; else return false; } </script> <td>$i</td> <td><a href=?modul=soal&aksi=tampil&id=$data[no_soal]>$data[soal] ?</a><br/>"; if ($data[no_soal]== $_GET[id]){ $i=0; $tampil2 = "SELECT * FROM soal_tes WHERE no_soal='$_GET[id]'"; $sql2 = mysql_query($tampil2); while($data2 = mysql_fetch_array($sql2)) { $i++; echo 'a. '.$data2[pilihan_a].'<br/>'; echo 'b. '.$data2[pilihan_b].'<br/>'; echo 'c. '.$data2[pilihan_c].'<br/>'; echo 'd. '.$data2[pilihan_d].'<br/>'; echo 'e. '.$data2[pilihan_e].'<br/>'; } } echo "</td> <td>$data[pilihan_benar]</td> <td align=center><a href=?modul=soal&aksi=tampil&id=".$data[no_soal]."><img src=./images/detail.png title=Detail></a></td> <td align=center><a href=?modul=soal&aksi=edit&id=".$data[no_soal]."><img src=./images/edit.png title=Edit></a></td> <td align=center><a href=modul/soal/aksi_soal.php?aksi=delete&id=".$data[no_soal]." onclick=\"return konfirmasi()\"><img src=./images/delete.png title=Hapus></a></td> </tr>"; } echo '</table>'; break; } ?>
4. aksi_soal.php
<?php include "../../config/koneksi.php"; $soal = ucfirst($_POST['soal']); $pilihan_benar = $_POST['pilihan_benar']; $pilihan_a = ucfirst($_POST['pilihan_a']); $pilihan_b = ucfirst($_POST['pilihan_b']); $pilihan_c = ucfirst($_POST['pilihan_c']); $pilihan_d = ucfirst($_POST['pilihan_d']); $pilihan_e = ucfirst($_POST['pilihan_e']); $no_soal = $_POST['no_soal']; $token = $_POST['token']; switch ($_GET['aksi']) { # Insert data case "insert" : $sql = "insert into soal_tes(no_soal,soal,pilihan_benar,pilihan_a,pilihan_b,pilihan_c,pilihan_d,pilihan_e,token) values('$no_soal','$soal','$pilihan_benar','$pilihan_a','$pilihan_b','$pilihan_c','$pilihan_d','$pilihan_e','$token')"; //echo "$sql";exit; $hasil = mysql_query($sql); if($hasil){ //pesan data berhasil disimpan echo " <script> window.location=\"../../?modul=soal&aksi=tampil\"; </script>"; } break; # Update data case "update" : $update = "UPDATE soal_tes SET no_soal = '$no_soal',soal = '$soal',pilihan_benar = '$pilihan_benar' ,pilihan_a = '$pilihan_a' ,pilihan_b = '$pilihan_b' ,pilihan_c = '$pilihan_c' ,pilihan_d = '$pilihan_d' ,pilihan_e = '$pilihan_e' WHERE no_soal='$no_soal'"; //echo "$update";exit; $hasil = mysql_query($update); if($update){ echo " <script> window.location=\"../../?modul=soal&aksi=tampil\"; </script>"; } break; # Delete data case "delete" : $delete="DELETE FROM soal_tes WHERE no_soal ='$_GET[id]'"; //echo $delete;exit; $hasil=mysql_query($delete); if($hasil){ echo " <script> window.location=\"../../?modul=soal&aksi=tampil\"; </script>"; } break; } ?>
Database
Tabel jawaban
Tabel soal
Tabel karyawan
BUTUH APLIKASI UJIAN ATAU TES ONLINE
HUBUNGI SISTEMPHP.COM
Postingan berikutnya
- ujian online php