Penggunaan database dengan HTML dan PHP - Pemrograman Web Dinamis
1. index.php
<html>
<head>
<title></title>
</head>
<body>
<form action="simpan.php" method="POST">
<table>
<tr>
<td>NIM</td>
<td> : </td>
<td><input type="text" name="nim"></td>
</tr>
<tr>
<td>Nama</td>
<td> : </td>
<td><input type="text" name="nama"></td>
</tr>
<tr>
<td>Alamat</td>
<td> : </td>
<td><textarea name="alamat"></textarea></td>
</tr>
<tr>
<td>No. Telepon</td>
<td> : </td>
<td><input type="" name="no_telp"></td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td> : </td>
<td>
<select>
<option> </option>
<option value="lk">Laki-laki</option>
<option value="pr">Perempuan</option>
</select>
</td>
</tr>
<tr>
<td>Program Studi</td>
<td> : </td>
<td>
<select>
<option> </option>
<option value="tif">Teknik Informatika</option>
<option value="te">Teknik Elektro</option>
<option value="ti">Teknik Industri</option>
<option value="tk">Teknik Kimia</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="masuk"></td>
</tr>
</form>
</body>
</html>
Hasil run :
2. simpan.php
<?php
$database= new mysqli("localhost","root","","prak3");
$nama=$_POST['nama'];
$nim=$_POST['nim'];
$alamat=$_POST['alamat'];
$sql = "insert into mhs (nim, nama, alamat) values ('$nim','$nama','$alamat')";
///$database->query($sql);
if ($database->query($sql) == true) {
echo "Berhasil Menyimpan Data<br> $nama, $nim, $alamat";
}
else{
echo "Gagal Menyimpan Data";
}
?>
<html>
<head>
<title></title>
</head>
<body>
<form action="simpan.php" method="POST">
<table>
<tr>
<td>NIM</td>
<td> : </td>
<td><input type="text" name="nim"></td>
</tr>
<tr>
<td>Nama</td>
<td> : </td>
<td><input type="text" name="nama"></td>
</tr>
<tr>
<td>Alamat</td>
<td> : </td>
<td><textarea name="alamat"></textarea></td>
</tr>
<tr>
<td>No. Telepon</td>
<td> : </td>
<td><input type="" name="no_telp"></td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td> : </td>
<td>
<select>
<option> </option>
<option value="lk">Laki-laki</option>
<option value="pr">Perempuan</option>
</select>
</td>
</tr>
<tr>
<td>Program Studi</td>
<td> : </td>
<td>
<select>
<option> </option>
<option value="tif">Teknik Informatika</option>
<option value="te">Teknik Elektro</option>
<option value="ti">Teknik Industri</option>
<option value="tk">Teknik Kimia</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="masuk"></td>
</tr>
</form>
</body>
</html>
Hasil run :
2. simpan.php
<?php
$database= new mysqli("localhost","root","","prak3");
$nama=$_POST['nama'];
$nim=$_POST['nim'];
$alamat=$_POST['alamat'];
$sql = "insert into mhs (nim, nama, alamat) values ('$nim','$nama','$alamat')";
///$database->query($sql);
if ($database->query($sql) == true) {
echo "Berhasil Menyimpan Data<br> $nama, $nim, $alamat";
}
else{
echo "Gagal Menyimpan Data";
}
?>
Komentar
Posting Komentar