Skip to content
Snippets Groups Projects
Commit ae1ce7ec authored by Eunice Sarah Siregar's avatar Eunice Sarah Siregar
Browse files

Revert "add: delete profile"

This reverts commit 09cd7caf.
parent 7abcd096
Branches
Tags
No related merge requests found
......@@ -14,34 +14,12 @@
$result = $mysqli->query($sql);
$user = $result->fetch_assoc();
}
// Fungsi untuk menghapus akun
function deleteAccount() {
if (isset($_POST['update_profile'])) {
$servername = "db";
$username = "php_docker";
$password = "password";
$dbname = "php_docker";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Koneksi ke database gagal: " . mysqli_connect_error());
}
$user_id = $_SESSION["user_id"];
$deleteUserQuery = "DELETE FROM user WHERE user_id = '$user_id'";
if (mysqli_query($conn, $deleteUserQuery)) {
session_destroy();
header("Location: /?login");
exit;
} else {
echo "Error: " . mysqli_error($conn);
}
}
if (isset($_POST['update_profile'])) {
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Koneksi ke database gagal: " . mysqli_connect_error());
}
......@@ -63,19 +41,20 @@
$newPhone = mysqli_real_escape_string($conn, $_POST['user_phone']);
}
// Validasi input sesuai kebutuhan Anda
// Update data pengguna di database
$updateQuery = "UPDATE user SET user_name = '$newName', user_email = '$newEmail', user_phone = '$newPhone' WHERE user_id = '$user_id'";
if (mysqli_query($conn, $updateQuery)) {
// Redirect atau berikan pesan sukses, misalnya:
header("Location: /?profile");
exit;
} else {
// Handle kesalahan jika gagal melakukan pembaruan
echo "Error: " . mysqli_error($conn);
}
}
if (isset($_POST['delete_account'])) {
deleteAccount();
}
?>
<!DOCTYPE html>
......@@ -112,7 +91,7 @@
<input type="text" id="user_phone" name="user_phone" value="<?= $user["user_phone"] ?>" disabled>
<button class="edit-button" id="edit-phone-button" type="button">Edit</button>
</div>
<button type="submit" id="delete_account" name="delete_account">Delete Account</button>
<button type="submit" id="update_profile" name="update_profile" style="display: none;">Update</button>
</form>
......
......@@ -39,49 +39,4 @@ document.addEventListener("DOMContentLoaded", function () {
updateProfileButton.style.display = "block";
}
}
// profile.js
// ...
const deleteAccountButton = document.getElementById("delete_account_button");
// Tambahkan event listener untuk tombol "Delete Account"
deleteAccountButton.addEventListener("click", function () {
const confirmDelete = confirm("Anda yakin ingin menghapus akun Anda?");
if (confirmDelete) {
// Redirect atau lakukan penghapusan akun di sini
deleteAccount();
}
});
function deleteAccount() {
// Lakukan permintaan AJAX atau penghapusan akun ke server di sini
// Setelah berhasil menghapus akun, lakukan langkah-langkah berikut:
// 1. Hapus semua session
// 2. Lakukan logout
// 3. Redirect ke halaman lain (misalnya halaman login)
// Contoh penghapusan semua session:
fetch("/logout.php", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
})
.then(function(response) {
if (response.ok) {
// Logout berhasil, arahkan ke halaman login atau halaman lain
window.location.href = "/login.php"; // Ganti dengan halaman yang sesuai
} else {
// Handle kesalahan jika logout gagal
console.error("Gagal logout");
}
})
.catch(function(error) {
console.error("Terjadi kesalahan:", error);
});
}
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment