Skip to content

Commit

Permalink
Pertemuan 10 - Praktikum 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Apr 18, 2024
1 parent fa05fea commit 51d3070
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
54 changes: 54 additions & 0 deletions pertemuan10/edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Data Anggota</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<?php

include('koneksi.php');


$id = $_GET['id'];
$query = "SELECT * FROM anggota WHERE id = $id";
$result = mysqli_query($connect, $query);
$row = mysqli_fetch_assoc($result);
mysqli_close($connect);
?>

<div class="container">
<h2>Edit Data Anggota</h2>
<form action="proses.php?aksi=ubah" method="post">
<input type="hidden" name="id" value="<?php echo $row['id']; ?> ">

<label for="nama">Nama:</label>
<input type="text" name="nama" id="nama" value="<?php echo $row['nama']; ?>" required>

<label for="jenis_kelamin" >Jenis Kelamin</label>
<div class="radio-group">
<input type="radio" name="jenis_kelamin" value="L" id="Laki"
<?php
if ($row['jenis_kelamin'] === 'L') echo 'checked';
?> required > <label for="laki">Laki-laki</label>
<input type="radio" name="jenis_kelamin" value="P" id="Perempuan"
<?php
if ($row['jenis_kelamin'] === 'p') echo 'checked';
?> required > <label for="perempuan">LPerempuan</label>
</div>
<label for="alamat">Alamat</label>
<input type="text" name="alamat" id="alamat" value="<?php echo $row['alamat']; ?>" required>

<label for="no_telp">No. Telp:</label>
<input type="text" name="no_telp" id="no_telp" value="<?php echo $row['no_telp']; ?>" required>

<button type="submit">Simpan Perubahan</button><a href="index.php" class="btn-kembali">Kembali</a>

</form>
</div>

</body>
</html>
2 changes: 1 addition & 1 deletion pertemuan10/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<td>" .$row["alamat"] . "</td>
<td>" .$row["no_telp"] . "</td>
<td>
<a href = 'edit.php?id =" .$row["id"] . "'>Edit</a>
<a href = 'edit.php?id=".$row["id"]."'>Edit</a>
<a href = '#' onclick = 'konfirmasiHapus(" .$row["id"] . ", \"".$row["nama"] . "\")'>Hapus</a>
</td>
</tr>";
Expand Down
15 changes: 15 additions & 0 deletions pertemuan10/proses.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
} else {
echo "Gagal menambahkan data: " . mysqli_error($connect);
}
} else if ($aksi == 'ubah'){
if (isset($_POST['id'])) {
$id = $_POST['id'];

$query = "UPDATE anggota SET nama = '$nama', jenis_kelamin = '$jenis_kelamin', alamat = '$alamat', no_telp = '$no_telp' WHERE id = '$id'";

if (mysqli_query($connect, $query) ) {
header("Location: index.php");
exit();
} else {
echo "Gagal mengupodate data: " . mysqli_error($connect);
}
} else{
echo "ID tidak valid";
}
}

mysqli_close($connect)
Expand Down

0 comments on commit 51d3070

Please sign in to comment.