I want to make questionnaire to show the test has done.
But, the answer button can't upload the answer to database.
I'm really confused.
This is my code named soal.php
(thats means question.php)
<?php
include "header2.php";
?>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "magang";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * from kuesioner";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "<div style='width:100%; border: 1px solid #EBEBEB; overflow:scroll;height:900px;'>";
echo '<table width="100%">';
$urut = 0;
while($row = $result->fetch_assoc()) {
$id_soal=$row["id_soal"];
$soal=$row["soal"];
$pilihan_a=$row["A"];
$pilihan_b=$row["B"];
$pilihan_c=$row["C"];
$pilihan_d=$row["D"];
?>
<form name="form1" method="post" action="jawab.php">
<input type="hidden" name="id_user[]" value=<?php echo $id_soal; ?>>
<input type="hidden" name="id_soal[]" value=<?php echo $id_soal; ?>>
<input type="hidden" name="jumlah" value=<?php echo $result->num_rows; ?>>
<tr>
<td width="17"><font color="#000000"><?php echo $urut=$urut+1; ?></font></td>
<td width="430"><font color="#000000"><?php echo "$soal"; ?></font></td>
</tr>
<td height="21"><font color="#000000"> </font></td>
<td><font color="#000000">
A. <input name="pilihan[<?php echo $id_soal; ?>]" type="radio" value="1">
<?php echo "$pilihan_a";?></font> </td>
</tr>
<tr>
<td><font color="#000000"> </font></td>
<td><font color="#000000">
B. <input name="pilihan[<?php echo $id_soal; ?>]" type="radio" value="2">
<?php echo "$pilihan_b";?></font> </td>
</tr>
<tr>
<td><font color="#000000"> </font></td>
<td><font color="#000000">
C. <input name="pilihan[<?php echo $id_soal; ?>]" type="radio" value="3">
<?php echo "$pilihan_c";?></font> </td>
</tr>
<tr>
<td><font color="#000000"> </font></td>
<td><font color="#000000">
D. <input name="pilihan[<?php echo $id_soal; ?>]" type="radio" value="4">
<?php echo "$pilihan_d";?></font> </td>
</tr>
<?php
}
} else {
echo "0 results";
}
$conn->close();
?>
<tr>
<td> </td>
<td><center><input type="submit" name="submit" value="Jawab" onclick="return confirm('Apakah Anda yakin dengan jawaban Anda?')"></center></td>
</tr>
</table>
</form>
</p>
</div>
But I already tried to make button for the answer, but I can't.
I can't create the right code for the answer button.
This my code for answers, named jawab.php
(answer.php)
<?php
mysql_connect("localhost","root","");
mysql_select_db("magang");
$id_soal=$_POST["id_soal"];
$pilihan = $_POST["pilihan"];
$no = 0 ;
foreach ($_POST['id_soal'] as $row) {
echo "<br>";
$a = $id_soal[$no];
echo $a;
echo "<b r>";
echo $pilihan[$a];
$no = $no + 1 ;
}
?>