Add account deletion functionality in account.php

This commit is contained in:
Fabian Schieder 2026-04-04 20:17:57 +02:00
parent e95e6e6d56
commit 05c318c334

View File

@ -43,6 +43,22 @@ $userId = (int)$_SESSION['user_id'];
*/ */
$conn = db_connect(); $conn = db_connect();
/**
* @brief Konto löschen
* Verarbeitet die Anfrage zum Löschen des eigenen Kontos.
*/
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_account'])) {
$delStmt = $conn->prepare("DELETE FROM users WHERE userID = ?");
$delStmt->bind_param('i', $userId);
$delStmt->execute();
$delStmt->close();
session_unset();
session_destroy();
header('Location: index.php');
exit();
}
/** /**
* @brief Vorbereiten der SQL-Abfrage zur Ermittlung der Benutzerdaten. * @brief Vorbereiten der SQL-Abfrage zur Ermittlung der Benutzerdaten.
* *
@ -252,6 +268,30 @@ include 'header.php';
</form> </form>
</div> </div>
<!-- Konto löschen -->
<!--
@brief Bereich zum Löschen des Kontos.
-->
<div class="auth__card account__section account__section--danger" style="margin-top: 2rem;">
<h2 class="account__section-title account__section-title--danger" style="color: #ef4444;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="3 6 5 6 21 6"></polyline>
<path d="M19 6V20a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
<line x1="10" y1="11" x2="10" y2="17"></line>
<line x1="14" y1="11" x2="14" y2="17"></line>
</svg>
Konto löschen
</h2>
<p class="account__danger-text">Diese Aktion ist unwiderruflich. Alle deine Daten werden gelöscht.</p>
<form action="account.php" method="post" onsubmit="return confirm('Bist du sicher, dass du dein Konto endgültig löschen möchtest? Diese Aktion kann nicht rückgängig gemacht werden!');">
<input type="hidden" name="delete_account" value="1">
<div class="auth__actions">
<button class="auth__submit" style="background-color: #ef4444; border-color: #ef4444;" type="submit">Konto unwiderruflich löschen</button>
</div>
</form>
</div>
</div> </div>
</section> </section>
</main> </main>