Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--FILE inputan
- <html>
- <head><title>Form 7 - Latihan 5</title></head>
- <body>
- <form action="proses7_database.php" method="POST">
- <table border='0' cellpadding='3' cellspacing='3' align='center'>
- <caption><strong>Formulir Biodata Mahasiswa</strong><br/><br/></caption><br/>
- <tr><td>Nama</td><td><input type="text" name="nama"/></td></tr>
- <tr><td>Jenis Kelamin</td><td>
- <label for="jeniskelamin"><input type="radio" name="jeniskelamin" value="pria"/>Pria</label>
- <label for="jeniskelamin"><input type="radio" name="jeniskelamin" value="wanita"/>Wanita</label>
- </td></tr>
- <tr><td>Tanggal Lahir</td><td>
- <select name="tanggal">
- <?php
- for($i=1;$i<=31;$i++){
- echo "<option value={$i}>{$i}</option>";
- }
- ?>
- </select>
- <select name="bulan">
- <?php
- $bulan=array(1=>'Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
- for($i=1;$i<=12;$i++){
- echo "<option value='{$i}'>{$bulan[$i]}</option>";
- }
- ?>
- </select>
- <select name="tahun">
- <?php
- for($i=1980;$i<=2004;$i++){
- echo "<option value='{$i}'>{$i}</option>";
- }
- ?>
- </select>
- </td></tr>
- <tr><td>Alamat</td><td><textarea cols="20" rows="5" name="alamat"/></textarea></td></tr>
- <tr><td></td>><td><input type="submit" name="kirim" value="kirim"/></td></tr>
- </table>
- </form>
- </body>
- </html>
- //-- FILE koneksi.php
- <?php
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='mahasiswa';
- $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
- //-- FILE proses7_database.php
- <?php
- include "koneksi.php";
- $namamhs = $_POST['nama'];
- $jeniskelamin = $_POST['jeniskelamin'];
- $tanggallahir = $_POST['tahun']."-".($_POST['bulan']<10?'0':'').$_POST['bulan']."-".($_POST['tanggal']<10?'0':'').$_POST['tanggal'];
- $alamat = $_POST['alamat'];
- $sql="INSERT INTO tbl_mhsiswa(nama_mhs, jenis_kelamin, tgl_lahir, alamat)VALUES('$namamhs','$jeniskelamin','$tanggallahir','$alamat');";
- $result=$db->query($sql);
- if($result)
- {
- echo "insert record berhasil<br/>";
- echo "Anda telah berhasil menginput data:";
- echo $namamhs,"<br/>",$jeniskelamin,"<br/>",$tanggallahir,"<br/>",$alamat,"<br/>";
- }
- else
- {
- echo "Gagal insert record";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement