bahasa program php

Membuat soal ujian online dengan pilihan ganda

good day, brother and sister pada kesempatan kali ini saya akan menyajikan tulisan mengenai
membuat soal ujian online dengan pilihan ganda.

berikut ini contoh penulisanya: dan contoh gambarnya:
soalujian.php

image

<head><title>soal fisika</title></head>
<body>
<?php
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$dbname="anggota";

$koneksi=mysqli_connect($dbhost,$dbuser,$dbpass);
if(mysqli_select_db($dbname,$koneksi)){
die("Gagal Koneksi: ".mysqli_connect_error($koneksi));
}else{
echo "";
}?>

image

<table border="0px"width="490px"cellpadding="4px"bgcolor="pink"align="left"><tr><form method="GET"action=""><td><textarea name="soalfisika"rows="3"cols="30"></textarea>><br/>
<input type="text"name="a"value=""><br/>
<input type="text"name="b"value=""><br/>
<input type="text"name="c"value=""><br/>
<input type="text"name="d"value=""><br/>
<input type="submit"value="buat soal"></td></form></tr></table>
<?php
$soalfisika=$_GET["soalfisika"];
$a=$_GET["a"];
$b=$_GET["b"];
$c=$_GET["c"];
$d=$_GET["d"];

if($soalfisika==false || $a==false || $b==false || $c==false || $d==false){
echo '<font style="color:red;font-size:21px;">ada yg kosong</font>';
}else{
$baris=array("$soalfisika","$a","$b","$c","$d");
$soalfisika1=$baris[0];
$a1=$baris[1];
$b1=$baris[2];
$c1=$baris[3];
$d1=$baris[4];

echo '<table border="0px"width="490px"cellpadding="4px"bgcolor="pink"align="left">';echo '<tr>';echo '<form method="POST"action="">';echo '<td>'.$soalfisika1.'<br/>';echo '<input type="radio"name="jawaban"value="'.$a1.'">'.$a1.'<br/>';echo '<input type="radio"name="jawaban"value="'.$b1.'">'.$b1.'<br/>';echo '<input type="radio"name="jawaban"value="'.$c1.'">'.$c1.'<br/>';echo '<input type="radio"name="jawaban"value="'.$d1.'">'.$d1.'<br/>';echo '<input type="submit"value="jawaban">';echo '</td>';echo '</form>';echo '</tr>';echo '</table>';
}?>

<?php
$jawaban=$_POST["jawaban"];
$sqlujian=mysqli_query("SELECT * FROM tblujian WHERE jawaban='$jawaban'",$koneksi);
if($jawaban==false){
if(mysqli_num_rows($sqlujian) >0){
$sqlujian=mysqli_query("DELETE * FROM tblujian WHERE jawaban='$jawaban'",$koneksi);
}else{
$sqlujian=mysqli_query('INSERT INTO tblujian(id,soalfisika,a,b,c,d,jawaban)VALUES("","$soalfisika1","$a1","$b1","$c1","$d1","$jawaban")',$koneksi);
}
echo "";
}else{
echo '<table border="0px"width="490px"cellpadding="4px"bgcolor="pink"align="left">';echo '<tr>';echo '<form method="GET"action="soalujian1.php">';echo '<td>';echo '<input type="hidden"name="soalfisika"value="'.$soalfisika1.'">';echo '<input type="hidden"name="a"value="'.$a1.'">';echo '<input type="hidden"name="b"value="'.$b1.'">';echo '<input type="hidden"name="c"value="'.$c1.'">';echo '<input type="hidden"name="d"value="'.$d1.'">';echo '<input type="hidden"name="jawaban"value="'.$jawaban.'">';echo '</td>';echo '</form>';echo '</tr>';echo '</table>';
echo '<br/><font style="color:blue;font-size:21px;font-weight:21bold;">'.$jawaban.'</font>';
}?>

</body>
</html>

berikut ini contoh penulisanya: dan contoh gambarnya:

image

soalujian1.php
<html>
<head><title>soal fisika</title></head>
<body>
<?php
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$dbname="anggota";

$koneksi=mysqli_connect($dbhost,$dbuser,$dbpass);
if(mysqli_select_db($dbname,$koneksi)){
die("Gagal Koneksi: ".mysqli_connect_error($koneksi));
}else{
echo "";

}?>

<?php
$soalfisika=$_GET["soalfisika"];
$a=$_GET["a"];
$b=$_GET["b"];
$c=$_GET["c"];
$d=$_GET["d"];
$jawaban=$_GET["jawaban"];

?>

<table border="0px"width="490px"cellpadding="4px"bgcolor="pink"align="left"><tr><form method="POST"action=""><td><?php echo $soalfisika;?><br/>
<input type="radio"name="jawaban2"value="<?php echo $a;?>"><?php echo $a;?><br/>
<input type="radio"name="jawaban2"value="<?php echo $b;?>"><?php echo $b;?><br/>
<input type="radio"name="jawaban2"value="<?php echo $c;?>"><?php echo $c;?><br/>
<input type="radio"name="jawaban2"value="<?php echo $d;?>"><?php echo $d;?><br/>
<input type="hidden"name="jawaban1"value="<?php echo $jawaban;?>"><input type="submit"value="jawaban"></td></form></tr></table>
<?php
$jawaban1=$_POST["jawaban1"];
if($jawaban1==false){
echo "";
}else{
$jawaban1=$_POST["jawaban1"];
}
$jawaban2=$_POST["jawaban2"];
if($jawaban2==false){
echo "";
}else{
$jawaban2=$_POST["jawaban2"];
echo '<font style="color:blue;">'.$jawaban2.'</font><br/>';
}?>

<?php
$jawaban1=$_POST["jawaban1"];
$jawaban2=$_POST["jawaban2"];
$jawaban2==$jawaban1;

$sqlujian1=mysqli_query("SELECT * FROM tblujian1 WHERE jawaban2='$jawaban2'",$koneksi);
if($jawaban2<>$jawaban1 || $jawaban2==false){
if(mysqli_num_rows($sqlujian1) >0){
$sqlujian1=mysqli_query("DELETE * FROM tblujian1 WHERE jawaban2='$jawaban2'",$koneksi);
}else{
$sqlujian1=mysqli_query('INSERT INTO tblujian1(id,soalfisika,a,b,c,d,jawaban1,jawaban2)VALUES("","$soalfisika","$a","$b","$c","$d","$jawaban1","$jawaban2")',$koneksi);
}
$jawaban2=$_POST["jawaban2"];
echo '<font style="color:red;font-size:21px;">salah</font>';
}else{
$jawaban2=$_POST["jawaban1"];
echo '<font style="color:green;font-size:21px;">benar</font>';
}?>

</body>
</html>
Demikianlah apa yang saya tulis mengenai cara pembuatan soal ujian online dengan pilihan ganda, semoga dapat dipahami.

Advertisements
Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s