Koneksi.php
Index.php<?php
require 'koneksi.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Tugas</title>
</head>
<body>
<table border="1" cellpadding="5">
<tr>
<th>No</th>
<th>Nama</th>
<th>Aksi</th>
</tr>
<?php
$no = 1;
$sql = mysqli_query($con, "SELECT * FROM projeklima");
foreach ($sql as $data) {
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $data["nama"]; ?></td>
<td>
<a href="hapus.php?id=<?= $data["id"]; ?>"> hapus </a>
<a href="edit.php?id=<?= $data["id"]; ?>"> edit </a>
</td>
</tr>
<?php } ?>
</table>
</body>
</html>
Hapus.php

Edit.php
Edit.php
<?php
require 'koneksi.php';
$id = $_GET['id'];
if (isset($_POST['submit'])) {
if (edit($_POST) > 0) {
echo "
<script>
alert('Data Berhasil Diubah');
document.location.href = 'index.php';
</script>
";
} else {
echo "
<script>
alert('Data Gagal Diubah');
</script>
";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit</title>
<form method="POST">
<?php
$sql = mysqli_query($con, "SELECT * FROM projeklima WHERE id = '$id'");
foreach ($sql as $row) {
?>
<h5 class="card-title text-center">Edit Data</h5>
<input type="number" name="id" value="<?php echo $id; ?>" hidden>
<input type="text" class="form-control" name="nama" id="nama" value="<?php echo $row["nama"]; ?>">
<label for="nama">Nama</label>
<?php } ?>
<input type="submit" name="submit" value="Edit Data" class="btn btn-warning mb-3 fw-bold">
</div>
</form>
</div>
</div>
</div>
</body>
</html>
No comments:
Post a Comment