Read 154 times | Created 2013-07-10 09:24:55 | Updated 2013-07-10 09:28:24 | | |

 

<?php  
/*  
DROP TABLE IF EXISTS `soal`;  
CREATE TABLE IF NOT EXISTS `soal` (  
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,  
  `soal` varchar(255) NOT NULL, 
  PRIMARY KEY (`id`)  
) ENGINE=MyISAM DEFAULT CHARSET=latin1;  
*/
//database configuration    
$dbhost='localhost';    
$dbuser='root';    
$dbpass='';    
$dbname='test';    
//database connection    
$db=new mysqli($dbhost,$dbuser,$dbpass,$dbname); 
$jml_soal=isset($_POST['jml'])?$_POST['jml']:1; 
if(isset($_POST['soal']))
{ 
  $sql="INSERT INTO soal(soal) VALUES ('".implode("'),('",$_POST['soal'])."')"; 
  $db->query($sql); 
} 
?> 
<!DOCTYPE html>  
<html>  
  <head>  
    <meta charset="utf-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1">  
    <title>Soal</title>  
  </head> 
  <body> 
    <form method='POST'> 
      <label>Masukkan Jumlah Soal</label><br/> 
      <input type="text" name="jml" value="<?php echo $jml_soal;?>" /> 
      <input type="submit" name="submit" value="submit" /> 
    </form> 
    <br/> 
    <form method='POST'> 
    <label>Masukkan Soal Ujian</label><br/> 
    <?php 
    for($i=1;$i<=$jml_soal;$i++) 
    { 
      echo "<textarea name='soal[]'></textarea><br/>n"; 
    } 
    ?> 
    <input type="submit" name="simpan" value="simpan" /> 
    </form> 
    <br/> 
    <table> 
    <?php 
    $sql="SELECT * FROM soal"; 
    $result=$db->query($sql); 
    if($result->num_rows>0) 
    { 
      while($row=$result->fetch_object()) 
      { 
         echo "<tr><td>{$row->id}</td><td>{$row->soal}</td></tr>n"; 
      } 
    } 
    ?> 
    </table> 
  </body> 
</html>