Advertisement
cdsatrian

input data mhs

Sep 8th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. //--FILE inputan
  2. <html>
  3.     <head><title>Form 7 - Latihan 5</title></head>
  4.     <body>
  5.         <form action="proses7_database.php" method="POST">
  6.             <table border='0' cellpadding='3' cellspacing='3' align='center'>
  7.             <caption><strong>Formulir Biodata Mahasiswa</strong><br/><br/></caption><br/>
  8.             <tr><td>Nama</td><td><input type="text" name="nama"/></td></tr>
  9.             <tr><td>Jenis Kelamin</td><td>
  10.                 <label for="jeniskelamin"><input type="radio" name="jeniskelamin" value="pria"/>Pria</label>
  11.                 <label for="jeniskelamin"><input type="radio" name="jeniskelamin" value="wanita"/>Wanita</label>
  12.             </td></tr>
  13.             <tr><td>Tanggal Lahir</td><td>
  14.             <select name="tanggal">
  15.             <?php
  16.                for($i=1;$i<=31;$i++){
  17.                     echo "<option value={$i}>{$i}</option>";
  18.                 }
  19.             ?>
  20.             </select>
  21.             <select name="bulan">
  22.             <?php
  23.               $bulan=array(1=>'Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
  24.               for($i=1;$i<=12;$i++){
  25.                 echo "<option value='{$i}'>{$bulan[$i]}</option>";
  26.               }
  27.               ?>
  28.             </select>
  29.             <select name="tahun">
  30.             <?php
  31.             for($i=1980;$i<=2004;$i++){
  32.                     echo "<option value='{$i}'>{$i}</option>";
  33.             }
  34.             ?>
  35.             </select>
  36.             </td></tr>
  37.             <tr><td>Alamat</td><td><textarea cols="20" rows="5" name="alamat"/></textarea></td></tr>
  38.             <tr><td></td>><td><input type="submit" name="kirim" value="kirim"/></td></tr>
  39.             </table>
  40.         </form>
  41.     </body>
  42. </html>
  43.  
  44. //-- FILE koneksi.php
  45. <?php
  46. $dbhost='localhost';
  47. $dbuser='root';
  48. $dbpass='';
  49. $dbname='mahasiswa';
  50. $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
  51.  
  52. //-- FILE proses7_database.php
  53. <?php
  54. include "koneksi.php";
  55. $namamhs = $_POST['nama'];
  56. $jeniskelamin = $_POST['jeniskelamin'];
  57. $tanggallahir = $_POST['tahun']."-".($_POST['bulan']<10?'0':'').$_POST['bulan']."-".($_POST['tanggal']<10?'0':'').$_POST['tanggal'];
  58. $alamat = $_POST['alamat'];
  59. $sql="INSERT INTO tbl_mhsiswa(nama_mhs, jenis_kelamin, tgl_lahir, alamat)VALUES('$namamhs','$jeniskelamin','$tanggallahir','$alamat');";
  60. $result=$db->query($sql);
  61. if($result)
  62.     {
  63.         echo "insert record berhasil<br/>";
  64.         echo "Anda telah berhasil menginput data:";
  65.         echo $namamhs,"<br/>",$jeniskelamin,"<br/>",$tanggallahir,"<br/>",$alamat,"<br/>";
  66.     }
  67. else
  68. {
  69.     echo "Gagal insert record";
  70. }
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement