misi, numpang tanya saya mempunyai tabel t_soal (no,soal,a,b,c,d dan kunci ) kemudian ada t_score (no,jawaban_anda,kunci,status) yang mau saya tanyakan, agar data inputan t_soal bisa terinput ke t_score itu bagaimna ? baru belajar php saya, kali aja ada yg berminat membantu saya, untuk codingan php'a terimakasih
<?php
include 'konek.php' ;
session_start();
$query = mysql_query("select * from t_soal" ) or die (mysql_error());
$_SESSION['soal' ] = array ();
$_SESSION['no' ] = 1 ;
$_SESSION['score' ] = 0 ;
$_SESSION['option' ] = array ();
$_SESSION['jawab' ] = array ();
$i=0 ;
while ($row = mysql_fetch_assoc($query)){
$_SESSION['soal' ][] = $row;
$_SESSION['option' ][] = array ($_SESSION['soal' ][$i]['a' ], $_SESSION['soal' ][$i]['b' ], $_SESSION['soal' ][$i]['c' ], $_SESSION['soal' ][$i]['d' ]);
$i++;
}
if (isset ($_SESSION['soal' ])){
header("location:tes.php" );
}
?>
<?php
session_start();
$soal = $_SESSION['soal' ];
$no = $_SESSION['no' ];
if (isset ($_POST['next' ])){
$_SESSION['jawab' ][] = $_POST['option' ];
if ($_POST['option' ] == $soal[$no-2 ]['kunci' ]){
$_SESSION['score' ] = $_SESSION['score' ] + 10 ;
}
}
if (isset ($soal[$no-1 ])){
?>
<!DOCTYPE html>
<html>
<head>
<title>Latihan Soal</title>
</head>
<body>
<a href="index.php" ></a>
<form action="" method="POST" >
<p>
<?php
echo $no.". " ; $_SESSION['no' ]++;
echo $soal[$no-1 ]['soal' ];
$jawaban = $_SESSION['option' ][$no-1 ];
shuffle($jawaban);
?>
</p>
<?php
for ($i=0 ; $i < 4 ; $i++) {
?>
<input type="radio" name="option" value="<?php echo $jawaban[$i]; ?>" required/> <?php echo $jawaban[$i]; ?> </br>
<?php
}
?>
<input type="submit" name="next" value="next" >
</form>
</body>
</html>
<?php
}else {
header("location:score.php" );
}
?>
<?php
include 'konek.php' ;
session_start();
$jawab = $_SESSION['jawab' ];
?>
<!DOCTYPE html>
<html>
<head>
<title>Hasil Test</title>
</head>
<body>
<h1>Hasil Latihan</h1>
<h2>SCORE ANDA: <?php echo $_SESSION['score' ]; ?> </h2>
<table border="1" >
<tr>
<td>NO</td>
<td>Jawaban Anda</td>
<td>Kunci Jawaban</td>
<td>Status</td>
</tr>
<?php
$i = 0 ;
$benar = $salah = 0 ;
$sql = mysql_query("select * from t_score" );
while ($key = mysql_fetch_array($sql)){
?>
<tr>
<td><?php echo $i+1 ; ?> </td>
<td><?php echo $jawab[$i] ?> </td>
<td><?php echo $key['kunci' ]; ?> </td>
<td>
<?php
if ($jawab[$i] == $key['kunci' ]) {
echo "Benar" ;
$benar++;
}else {
echo "Salah" ;
$salah++;
}
?>
</td>
</tr>
<?php
$i++;
}
?>
</table>
<h3>Benar: <?php echo $benar; ?> <br>
Salah: <?php echo $salah; ?> </h3>
<a href="index.php" >Kembali</a>
</body>
</html>
untuk ditampilkan di tabel score, bagaimna source code'a terimakasih