<?php
session_start();
if($_SESSION['id_siswa']!=''){
include"../inc/conn.php";

$id_siswa   = str_replace("'","`",(isset($_POST['id_siswa'])) ? $_POST['id_siswa'] : "");
$id_unit    = str_replace("'","`",(isset($_POST['id_unit'])) ? $_POST['id_unit'] : "");
$id_pretest   = str_replace("'","`",(isset($_POST['id_pretest'])) ? $_POST['id_pretest'] : "");

$count = count($id_pretest);
for($i=0;$i<$count;$i++){

  $simpan = mysqli_query($connect,"insert into tb_jawaban_pretest set

    id_siswa      = '".$id_siswa."',
    id_unit       = '".$id_unit."',
    id_pretest    = '".$id_pretest[$i]."',
    jawaban       = '".$_POST['jawaban'.$id_pretest[$i]]."'") or die(mysqli_error($connect));

}

echo"<script>alert('Jawaban anda telah tersimpan !');</script>";
echo"<script>document.location.href='pretest.php?id=$id_unit'</script>";



}else{
  echo"<script>document.location.href='index.php'</script>";
}
?>