Koneksi dan tambah data dengan PHP pada database.
Koneksi dan tambah data dengan PHP pada database.
Source Code :
index.php
<?php
require 'koneksi.php';
$data = mysqli_query($koneksi, "SELECT * FROM tamu");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
<div class="row justify-content-center align-item-center top-50">
<h1 class="text-center" style="margin-top: 50px;">Buku Tamu</h1>
<button type="button" class="btn btn-primary w-25 start" data-bs-toggle="modal" data-bs-target="#exampleModal">
Tambah Tamu
</button>
</div>
</div>
<div class="container-fluid">
<div class="row justify-content-center align-item-center top-50">
<table class="table table-bordered table-hover w-75" style="margin-top: 15px;">
<thead>
<th>No</th>
<th>Nama</th>
<th>Email</th>
<th>Pesan</th>
</thead>
<?php
$no = 1;
foreach ($data as $row) {
?>
<tbody>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $row["nama"]; ?></td>
<td><?php echo $row["email"]; ?></td>
<td><?php echo $row["pesan"]; ?></td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Tambah Tamu</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="POST" action="modal.php?act=tambahuser">
<div class="form-floating mb-3">
<input type="text" class="form-control" id="nama" name="nama" placeholder="nama">
<label for="nama">Nama Tamu</label>
</div>
<div class="form-floating">
<input type="email" class="form-control" id="email" name="email" placeholder="email">
<label for="email">Email Tamu</label>
</div>
<div class="form-floating mt-3">
<textarea class="form-control" placeholder="Leave a comment here" id="pesan" name="pesan" style="height: 100px"></textarea>
<label for="pesan">Pesan</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
<input type="submit" name="submit" class="btn btn-primary" value="Submit">
</form>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
</body>
</html>
Komentar
Posting Komentar