I have a problem, I want to create a popup for my forum which says "Are you sure you want to delete on category?" and if click on yes, delete the category. But I have a problem, my sql request deletes all categories and not only one. Can you help me?
The code (Commented for you):
while ($c = mysqli_fetch_assoc($result)) { // The wile
if (isset($_SESSION['steamid'])) { // Check if user connected
include('../script/steamlogin/userInfo.php');
if (IsAdmin($steamprofile['steamid'])) { // Check if user is an admin
?>
<p class="cat tooltip"><?=$c['name']?> <a href="#" class="tooltiptext whitebar remove_openpopup">Remove</a> </p> <!-- Button which open the popup -->
<div id="popup" class="popup"> <!-- The popup -->
<div class="popup_content">
<p>Are you sure you want to delete this category?</p>
<button class="button_popup close_button">No</button>
<button class="button_popup close_button" onclick='document.getElementById("remove").submit()'>Yes</button>
</div>
</div>
<form id="remove" method="post"><input type="hidden" name="remove" /></form> <!-- The form affected by the popup -->
<script type="text/javascript" src="../style/js/popup.js"></script>
<?php
if (isset($_POST['remove'])) { // The remove script
if (isset($_SESSION['steamid'])) {
include('../script/steamlogin/userInfo.php');
if (IsAdmin($steamprofile['steamid'])) {
mysqli_query($base, 'DELETE FROM `forum_categories` WHERE `id`="'.$c['id'].'"');
header('Location: index.php');
}
}
}
JS:
var modal = document.getElementById("popup");
var btns = Array.prototype.slice.call(document.querySelectorAll(".remove_openpopup"));
var span = document.querySelectorAll(".close_button")[0];
btns.forEach(function(btn) {
btn.onclick = function() {
modal.style.display = "block";
}
});
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
I think its cause of the unique name
remove, I think fix this with a array variable but how can I make and unlimited array value?
My idea:
$name = array('1' => 'remove1', '2' => 'remove2', '3' => 'remove3');
And after:
$c[$name][$VARIABLE WHICH COUNT THE WHILE]
Do you see what I mean? Have you got an idea? (For make the array unlimited)