-- Database: `ok`
--
-- --------------------------------------------------------
--
-- Table structure for table `banksoal`
--
CREATE TABLE IF NOT EXISTS `banksoal` (
`soalid` int(5) NOT NULL AUTO_INCREMENT,
`topik` varchar(50) NOT NULL,
`pertanyaan` text,
`pilihan_a` tinytext,
`pilihan_b` tinytext,
`pilihan_c` tinytext,
`pilihan_d` tinytext,
`pilihan_e` tinytext,
`jawaban` varchar(1) DEFAULT NULL,
`gpertanyaan` varchar(100) DEFAULT NULL,
`gpilihan_a` varchar(100) DEFAULT NULL,
`gpilihan_b` varchar(100) DEFAULT NULL,
`gpilihan_c` varchar(100) DEFAULT NULL,
`gpilihan_d` varchar(100) DEFAULT NULL,
`gpilihan_e` varchar(100) DEFAULT NULL,
PRIMARY KEY (`soalid`),
KEY `topik` (`topik`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=273 ;
<?php
if($_POST){
$sql = "insert into banksoal set pertanyaan='".$_POST['pertanyaan']."'";
foreach($_FILES['file']['name'] as $i => $name){
if($_FILES['file']['error'][$i] != 0){
continue;
}
move_uploaded_file($_FILES['file']['tmp_name'][$i], 'path/to/upload/'.$name);
$sql .=",gpilihan_".$i."='".$name."'";
}
mysql_query($sql);
}
?>
<form method="post" action="" enctype="multipart/form-data">
pertanyaan <textarea value="pertanyaan"></textarea>
gambar a <input type="file" name="file[a]"/>
gambar b <input type="file" name="file[b]"/>
gambar c <input type="file" name="file[c]"/>
gambar d <input type="file" name="file[d]"/>
gambar e <input type="file" name="file[e]"/>
<input type="submit" name="save" value="save"/>
</form>
<div>
<?php
include "koneksi.php";
if (isset($_POST['submit'])){
$topik=$_POST['topik'];
$pertanyaan=$_POST['pertanyaan'];
$pilihan_a=$_POST['pilihan_a'];
$pilihan_b=$_POST['pilihan_b'];
$pilihan_c=$_POST['pilihan_c'];
$pilihan_d=$_POST['pilihan_d'];
$pilihan_e=$_POST['pilihan_e'];
$jawaban=$_POST['jawaban'];
$letakFile=$_FILES['file']['temp_name'];
$namaFile=$_FILES['file']['name'];
$jmlFile = 6;
$ulang=0;
while($ulang<$jmlFile){
if($namaFile[$ulang]!=""){
$folder="gambar/$namaFile[$ulang]";
move_uploaded_file($letakFile[$ulang],"$folder");
$query = "insert into banksoal values ('','$topik','$pertanyaan','$pilihan_a','$pilihan_b','$pilihan_c','$pilihan_d','$pilihan_e','$jawaban','$namaFile[1]','$namaFile[2]','$namaFile[3]','$namaFile[4]','$namaFile[5]','$namaFile[6]')";
$input = (mysql_query($query));
if($input){
?>
<script language="javascript">document.location.href="validasi.php";</script><?php
}else{
echo mysql_error();}
}else{
unset($_POST['submit']);
}}}
?>
<h1>Input Soal</h1>
<form action="soal.php" method="post" enctype="multipart/form-data">
<table class="datatable" align="center">
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><b>TOPIK</b></p>
</font></td>
<td> <select name="topik">
<option value="diksi">Diksi</option>
<option value="pemahaman wacana">Pemahaman Wacana</option>
<option value="logika verbal">Logika Verbal</option>
<option value="deret angka">Deret Angka</option>
<option value="penalaran aritmatika">Penalaran Aritmatika</option>
<option value="korelasi makna">Korelasi Makna</option>
</select> </td>
</tr>
<tr>
<td width="29%" height="37" valign="top"><font size="2" face="verdana">
<p><strong>Pertanyaan</strong></p>
</font></td>
<td><textarea cols="23" rows="5" name="pertanyaan"></textarea></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[]" id="file1"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan A</strong></p>
</font></td>
<td><input type="text" name="pilihan_a" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[]" id="file2"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan B</strong></p>
</font></td>
<td><input type="text" name="pilihan_b" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[]" id="file3"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan C</strong></p>
</font></td>
<td><input type="text" name="pilihan_c" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[]" id="file4"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan D</strong></p>
</font></td>
<td><input type="text" name="pilihan_d" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[]" id="file5"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan E</strong></p>
</font></td>
<td><input type="text" name="pilihan_e" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[]" id="file6"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>JABAWAN</strong></p>
</font></td>
<td> <select name="jawaban">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
<option value="d">D</option>
<option value="e">E</option>
</select> </td>
</tr>
<tr>
<td> </td>
<td width="71%"><input name="submit" type="submit" value="Submit" /> </td>
</tr>
</table>
</form>
</div>
<div>
<?php
//include "koneksi.php";
if ($_POST){
$topik=$_POST['topik'];
$pertanyaan=$_POST['pertanyaan'];
$pilihan_a=$_POST['pilihan_a'];
$pilihan_b=$_POST['pilihan_b'];
$pilihan_c=$_POST['pilihan_c'];
$pilihan_d=$_POST['pilihan_d'];
$pilihan_e=$_POST['pilihan_e'];
$jawaban=$_POST['jawaban'];
$sql = "insert into banksoal set
topik='$topik',
pertanyaan='$pertanyaan',
pilihan_a='$pilihan_a',
pilihan_b='$pilihan_b',
pilihan_c='$pilihan_c',
pilihan_d='$pilihan_d',
pilihan_e='$pilihan_e',
jawaban='$jawaban'";
//upload gambar pertanyaan
if($_FILES['gambar']['name'] != '' && $_FILES['gambar']['error'] == 0){
move_uploaded_file($_FILES['gambar']['tmp_name'], "gambar/".$_FILES['gambar']['name']);
$sql .= ",gpertanyaan='".$_FILES['gambar']['name']."'";
}
//upload gambar pilihan
foreach($_FILES['file']['name'] as $pilihan => $name){
if($_FILES['file']['error'][$pilihan] != 0){
continue;
}
move_uploaded_file($_FILES['file']['tmp_name'][$pilihan],"gambar/$name");
$sql .= ",gpilihan_$pilihan='$name'";
}
$result = mysql_query($sql);
if($result){
echo '<script language="javascript">document.location.href="validasi.php";</script>';
}else{
echo mysql_error();
}
}
?>
<h1>Input Soal</h1>
<form action="" method="post" enctype="multipart/form-data">
<table class="datatable" align="center">
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><b>TOPIK</b></p>
</font></td>
<td> <select name="topik">
<option value="diksi">Diksi</option>
<option value="pemahaman wacana">Pemahaman Wacana</option>
<option value="logika verbal">Logika Verbal</option>
<option value="deret angka">Deret Angka</option>
<option value="penalaran aritmatika">Penalaran Aritmatika</option>
<option value="korelasi makna">Korelasi Makna</option>
</select> </td>
</tr>
<tr>
<td width="29%" height="37" valign="top"><font size="2" face="verdana">
<p><strong>Pertanyaan</strong></p>
</font></td>
<td><textarea cols="23" rows="5" name="pertanyaan"></textarea></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="gambar" id="file1"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan A</strong></p>
</font></td>
<td><input type="text" name="pilihan_a" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[a]" id="file2"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan B</strong></p>
</font></td>
<td><input type="text" name="pilihan_b" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[b]" id="file3"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan C</strong></p>
</font></td>
<td><input type="text" name="pilihan_c" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[c]" id="file4"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan D</strong></p>
</font></td>
<td><input type="text" name="pilihan_d" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[d]" id="file5"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>Pilihan E</strong></p>
</font></td>
<td><input type="text" name="pilihan_e" size="30"/></td>
</tr>
<tr>
<td height="37" valign="middle"><font size="2" face="verdana">Gambar</font></td>
<td><input type="file" name="file[e]" id="file6"></td>
</tr>
<tr>
<td width="29%" height="37" valign="middle"><font size="2" face="verdana">
<p><strong>JABAWAN</strong></p>
</font></td>
<td> <select name="jawaban">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
<option value="d">D</option>
<option value="e">E</option>
</select> </td>
</tr>
<tr>
<td> </td>
<td width="71%"><input name="submit" type="submit" value="Submit" /> </td>
</tr>
</table>
</form>
</div>