Membuat Aplikasi dari Dasar
Praktek 1
Membuat form input yang disambungkan ke database lalu ditampilkan di browser
Source code
koneksi.php
<?php
$host = mysqli_connect("localhost","root","db_praktek");
?>
form.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ujicoba</title>
</head>
<body>
<form method="POST" action="input_nama.php">
<label>Nama : </label><input type="text" name="nama"><br><br>
<input type="submit" name="submit">
<input type="reset" name="reset">
</form>
</body>
</html>
input_nama.php
<?php
include "koneksi.php";
$nama = $_POST['nama'];
$input = "insert into project (nama) values ('$nama')";
$hasil=mysqli_query($host, $input);
if($hasil){
echo "proses input berhasil";
}
else{
echo "proses input tidak berhasil";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ujicoba</title>
</head>
<body>
<br><br>
<a href="form.php">Isi Data lagi</a>
<br>
<a href="tampilan_data.php">Tampilkan seluruh data</a>
</body>
</html>
tampilan_data.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ujicoba</title>
</head>
<body>
<center><table border="2" cellpadding="10">
<tr>
<th>ID</th>
<th>Nama</th>
</tr>
<?php
include 'koneksi.php';
$hasil = mysqli_query($host,"SELECT * FROM project ORDER BY id DESC LIMIT 1");
foreach ($hasil as $data) {
?>
<tr>
<td><?php echo $data["id"]; ?></td>
<td><?php echo $data["nama"]; ?></td>
</tr>
<?php } ?>
</table></center>
</body>
</html>
Tabel di database mysql
Komentar
Posting Komentar