prepare("SELECT email, (NOW() > request_date + INTERVAL 1 DAY) AS expired FROM requests_email WHERE id = ? AND user = ?"); if (!$statement) { http_response_code(500); $errorMessage = "An unexpected error occurred while changing the email address."; } else { $statement->bind_param('si', $_GET['id'], $_SESSION['user']); $statement->execute(); $result = $statement->get_result(); if (!$result) { http_response_code(500); $errorMessage = "An unexpected error occurred while changing the email address."; $statement->close(); } else { $request = $result->fetch_assoc(); $statement->close(); if (!$request) { http_response_code(400); $errorMessage = "Invalid request ID."; } else { $expired = false; if ($request['expired']) { $expired = true; http_response_code(400); $errorMessage = "Invalid request ID."; } if (!$expired) { $statement = $connection->prepare("UPDATE users SET email = ? WHERE id = ?"); if (!$statement) { http_response_code(500); $errorMessage = "An unexpected error occurred while changing the email address."; } else { $statement->bind_param('si', $request['email'], $_SESSION['user']); if (!$statement->execute()) { http_response_code(500); $errorMessage = "An unexpected error occurred while changing the email address."; } $statement->close(); } } } $statement = $connection->prepare("DELETE FROM requests_email WHERE id = ? AND user = ?"); if (!$statement) { http_response_code(500); $errorMessage = "An unexpected error occurred while changing the email address."; } else { $statement->bind_param('si', $_GET['id'], $_SESSION['user']); if (!$statement->execute()) { http_response_code(500); $errorMessage = "An unexpected error occurred while changing the email address."; } $statement->close(); } } } } if ($errorMessage) { $pageTitle = "Your email address hasn't been changed"; $pageDescription = $errorMessage; } else { $pageTitle = "Your email address has been changed"; $pageDescription = "Your email address has been changed."; } include 'header.php'; ?>

Return to home