-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_all_flashcards.php
60 lines (51 loc) · 2.05 KB
/
delete_all_flashcards.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
// Include database connection
include 'db_connection.php';
// Validate access code
$access_code = $_GET['access_code'];
$table_name = mysqli_real_escape_string($conn, $access_code);
$check_table_query = "SHOW TABLES LIKE '$table_name'";
$result = $conn->query($check_table_query);
if ($result->num_rows != 1) {
header("Location: login.php");
exit;
}
// Check if proceed button is clicked
if (isset($_POST['proceed'])) {
// Perform deletion query
$query = "DELETE FROM $table_name"; // Use $table_name instead of $accessCode
$result = mysqli_query($conn, $query);
if ($result) {
// Deletion successful, redirect to list page
header("Location: list.php?access_code=$access_code");
exit;
} else {
// Store error message
$deletionError = '<div class="info">خطا در حذف تمامی فلش کارت ها: ' . mysqli_error($conn) . '</div>';
}
}
// Header
$page_title = "ایجاد فلش کارت جدید"; include 'header.php';
// Display error message if it exists
if (!empty($deletionError)) {
echo $deletionError;
}
// Limited accounts
$limited_accounts = ['idioms', 'idiomsadv'];
?>
<div class="question">از حذف تمامی فلش کارت های خود مطمئنید؟</div>
<form action="delete_all_flashcards.php?access_code=<?php echo $access_code; ?>" method="post" class="column reset" <?php if (in_array($_GET['access_code'], $limited_accounts)) echo 'onsubmit="return false;"'; ?>>
<button type="submit" name="proceed" class="button <?php if (in_array($_GET['access_code'], $limited_accounts)) echo "limited"; ?>">ادامه</button>
<button type="button" id="cancel" class="button secondary">لغو</button>
</form>
<script>
// Cancel
document.getElementById('cancel').addEventListener('click', function() {
var urlParams = new URLSearchParams(window.location.search);
var accessCode = urlParams.get('access_code');
window.location.href = 'list.php?access_code=' + accessCode;
});
</script>
<!-- Footer -->
</div>
<?php include 'footer.php'; ?>