input soall

Rheyank Iwan Nytt · Jul 24, 2013
mas mau nanya ,, saya buat input soal dengan 2 text area ,, tpi masih gagal ..
data uda berhasil diinput tapi dalam database tidak tersimpan ,, pa da yang salah ,,
ne scriptnya .
input.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>English Lesson Of Grammar</title>
<link href="css/rheyank_style.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/ddsmoothmenu.js">

/***********************************************
* Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

</script>

<script type="text/javascript">

ddsmoothmenu.init({
	mainmenuid: "menu", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

</script>
<style type="text/css">
<!--
.style1 {color: #75a62c}
.style2 {
	color: #333;
	font-weight: bold;
}
-->
</style>
</head>
<body>

<div id="body">
	<div id="header"></div> 
	<!-- end of header -->
    
    <div id="menu" class="ddsmoothmenu">
        <ul>
            <li><a href="index.php">Home</a></li>
            <li><a href="grammar.php">Grammar</a></li>
          	<li><a href="soal.php" class="selected">Excercise</a></li>
          	<li><a href="about.php">About</a></li>
        </ul>
        <br style="clear: left" />
    </div> <!-- end of menu -->

    <div id="main">    	
	    <h2>Masukan Soal !!! </h2>
        <div class="col_l">
            <br class="cleaner h20" />
            <div id="contact_form">
			      <form name="formsoal" id="formsoal" method="post" action="simpansoal.php">  
							<p>
			                <label for="soal">SOAL</label> 
                            <textarea id="soal" name="soal[1]" rows="40" cols="10" class="ckeditor"></textarea>
   							</p>
                            <p>
                                <label for="j1">Jawaban A</label> 
                                <input type="text" name="j1[1]" class="required input_field" />
                            </p>
                            <p>
                                <label for="j2">Jawaban B</label> 
                                <input type="text" name="j2[1]" class="validate-email required input_field" />
                            </p>
							<p>
                                <label for="j3">Jawaban C</label> 
                                <input type="text" name="j3[1]" class="validate-email required input_field" />
                            </p>
							<p>
                                <label for="j4">Jawaban D</label> 
                                <input type="text" name="j4[1]" class="validate-email required input_field" />
                            </p>
							<p class="no_margin_right">
                                <label for="jbenar[1]">Kunci Jawaban</label> 
                                <input type="text" name="jbenar" class="input_field" />
                            </p>
							<p class="no_margin_right">
                                <label for="tipe">Materi</label> 
                                <input type="text" name="tipe[1]" class="input_field" />
                            </p>
							<p>
			                <label for="soal">SOAL</label> 
                            <textarea id="soal" name="soal[2]" rows="0" cols="0" class="ckeditor"></textarea>
   							</p>
                            <p>
                                <label for="j1">Jawaban A</label> 
                                <input type="text" name="j1[2]" class="required input_field" />
                            </p>
                            <p>
                                <label for="j2">Jawaban B</label> 
                                <input type="text" name="j2[2]" class="validate-email required input_field" />
                            </p>
							<p>
                                <label for="j3">Jawaban C</label> 
                                <input type="text" name="j3[2]" class="validate-email required input_field" />
                            </p>
							<p>
                                <label for="j4">Jawaban D</label> 
                                <input type="text" name="j4[2]" class="validate-email required input_field" />
                            </p>
                            <p class="no_margin_right">
                                <label for="jbenar">Kunci Jawaban</label> 
                                <input type="text" name="jbenar[2]" class="input_field" />
                            </p>
							<p class="no_margin_right">
                                <label for="tipe">Materi</label> 
                                <input type="text" name="tipe[2]" class="input_field" />
                            </p>
                            <div class="cleaner h20"></div>
            							
                            <input type="submit" value="Save" id="submit" name="submit" class="submit_btn float_l" />
                            <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" />
                      </form>
	            </div> 
        </div>
		        <br class="cleaner" />
    </div> <!-- end of main -->
    
    <div id="footer"></div>
        <div class="cleaner"></div>
</div> <!-- end of footer -->

<div id="cr_bar_wrapper">
	<div id="cr_bar">
    	Copyright © 2013 Designed by <a href="http://www.facebook.com/rheyank.iwan">Rheyank Iwan</a>    </div>
</div>

</body>
</html>

ne script simpannya mas .
simpan.php
<?
//Cek Tombol 
foreach ($_POST){
//Kirimkan Variabel
$soal = $_POST['soal[1]'];
$j1 = $_POST['j1[1]'];
$j2 = $_POST['j2[1]'];
$j3 = $_POST['j3[1]'];
$j4 = $_POST['j4[1]'];
$jbenar = $_POST['jbenar[1]'];
$tipe = $_POST['tipe[1]'];
$soal = $_POST['soal[2]'];
$j1 = $_POST['j1[2]'];
$j2 = $_POST['j2[2]'];
$j3 = $_POST['j3[2]'];
$j4 = $_POST['j4[2]'];
$jbenar = $_POST['jbenar[2]'];
$tipe = $_POST['tipe[2]'];

//validasi data jika pesan kosong
if (empty($_POST['soal[1]'])|| empty($_POST['j1[1]'])|| empty($_POST['j2[1]'])|| empty($_POST['j3[1]'])|| empty($_POST['j4[1]'])|| empty($_POST['jbenar[1]'])|| empty($_POST['tipe[1]'])|| empty($_POST['soal[2]'])|| empty($_POST['j1[2]'])|| empty($_POST['j2[2]'])|| empty($_POST['j3[2]'])|| empty($_POST['j4[2]'])|| empty($_POST['jbenar[2]'])|| empty($_POST['tipe[2]'])) 
{
?>
<script language="JavaScript">
alert('Data Harap Dilengkapi');
document.location='inputsoal.php';
</script>
<?
}
//Jika Validasi Terpenuhi
else
{
//Memanggil File Koneksi Database
mysql_connect("localhost", "root", "12345");
mysql_select_db("english");

//Masukan data ke Table siswa
     $query ="INSERT INTO soal VALUES('$id','$soal','$j1','$j2','$j3','$j4','$jbenar','$tipe')";
     $hasil = mysql_query($query);  
     if($hasil){  
//Jika Sukses
//echo "Data telah diinput";
?>
<script language="JavaScript">
alert('Data Berhasil diinput');
document.location='viewsoal.php';
</script>
<?

}
else
{
//Jika Gagal
//echo "Data gagal diinput, Silakan Ulangi";
}
}
}
?>
<script language="JavaScript">
alert('Data Gagal diinput,, Silakan ulangi');
document.location='inputsoal.php';
</script>
mhon bantuannya mas ,, sukses slalu
Silahkan login untuk menjawab!
0
Loading...
Robert James M · Jul 25, 2013 · 0 Suka · 0 Tidak Suka
itu ko $j1, $j2, $j3 ada beberapa?
0
Loading...
Rheyank Iwan Nytt · Jul 25, 2013 · 0 Suka · 0 Tidak Suka
$j1, $j2, $j3, $j4, $jbenar, $tipe . . . . masing" da dua mas .. kan da 2 form input .. tpi menggunakan 1 button simpan ,, naa untuk script simpannya tuch pa da yg slah ?? soalnya uda ada peringatan data tersimpan , tpi didalam database tidak tersimpan ..
0
Loading...
Robert James M · Jul 28, 2013 · 0 Suka · 0 Tidak Suka
kalo dua duanya mau masuk ke database sekaligus ya ga bisa cara biasa, kayanya itu itungannya array deh insertnya ...
kayanya loh
:P
0
Loading...
Rheyank Iwan Nytt · Jul 29, 2013 · 0 Suka · 0 Tidak Suka
ea mas . . lah q gtw proses loopingnya tu gmn . . bsa kasih pencerahan gag mas . . tlong ea
0
Loading...
Ellyx Christian · Aug 2, 2013 · 0 Suka · 0 Tidak Suka
<?
//Cek Tombol 
mysql_connect("localhost", "root", "12345");
mysql_select_db("english");
foreach ($_POST['soal'] as $i => $soal){
	$j1 = $_POST['j1'][$i];
	$j2 = $_POST['j2'][$i];
	$j3 = $_POST['j3'][$i];
	$j4 = $_POST['j4'][$i];
	$jbenar = $_POST['jbenar'][$i];
	$tipe = $_POST['tipe'][$i];
	if($j1 && $j2 && $j3 && $j4 && $soal && $jbenar && $tipe){
		//Masukan data ke Table siswa
		$query ="INSERT INTO soal VALUES('$id','$soal','$j1','$j2','$j3','$j4','$jbenar','$tipe')";
		$hasil = mysql_query($query);  
	}else{
		?>
		<script language="JavaScript">
		alert('Data Harap Dilengkapi');
		document.location='inputsoal.php';
		</script>
		<?php
	}
}
?>
<script language="JavaScript">
alert('Data Berhasil diinput');
document.location='viewsoal.php';
</script>
0
Loading...
Rheyank Iwan Nytt · Aug 5, 2013 · 0 Suka · 0 Tidak Suka
mkc mas ,,,,:)