Membuat Aplikasi
1. membuat koneksi ke database
2. crud.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<?php include 'koneksi.php'; ?>
</head>
<body>
<form action="hasil.php" method="post">
<table>
<tr>
<td>Nama</td>
<td>:</td>
<td>
<input type="text" name="namaku" placeholder="Nama Anda">
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" name="submit">Submit</button>
</td>
<td>
<button type="reset">Reset</button>
</td>
</tr>
</table>
</form>
</body>
</html>
Hasilnya:
3. hasil.php
<?php
include 'koneksi.php';
if (isset($_POST['submit'])) {
$nama = $_POST['namaku'];
include 'koneksi.php';
$hasil = "insert into contoh(id,nama) values('','$nama')";
$input = mysqli_query($db, $hasil);
}
$hasil = mysqli_query($db, "select * from contoh");
foreach ($hasil as $data){
?>
<table border="3">
<tr>
<td>
<?php echo $data['id']; ?>
</td>
<td>
<?php echo $data['nama']; ?>
</td>
</tr>
</table>
<?php } ?>
Hasilnya:
Comments
Post a Comment