I have some page with same html elements:
<form action="" method="post" id="form" class="form">
<div id="div3">
<input type="hidden" name="3" id="3" hidden="true" value="27">
<input type="text" name="task3" id="task3" class="task input" placeholder="Enter Task" required="required" value="SOME VALUE">
<input class="input hover-to-show" type="button" name="removetask3" id="removetask3" value="Remove" onclick="remove(3)">
</div> //'3' is an id of the element
<input style="position: fixed; right: 0;" name="done" type="submit" value="Save" />
</form>
And there is a script remove(j):
function remove(j) {
id--;
let element = document.getElementById("div" + j);
let input = document.getElementById("task"+j);
input.setAttribute("value", " ");
element.parentNode.removeChild(element);
}
And then i have php code with SQL statements:
if(isset($_POST["done"])){
for($i = 1; $i < $count; $i++){
if(htmlspecialchars(trim($_POST["task".$i])))
{
$index = $_POST[$i];
$task = htmlspecialchars(trim($_POST["task".$i]));
$imp = htmlspecialchars(trim($_POST["mark".$i]));
mysqli_query($db, "UPDATE `data` SET `tasks`='$task',`imp`= '{$imp}' WHERE `id` = {$index} AND `customerid`={$id}");
if($i > $rnum){
mysqli_query($db, "INSERT INTO `data` (`customerid`, `tasks`, `imp`) VALUES ({$id}, '{$task}', {$imp})");
}
}
else{
mysqli_query($db, "DELETE FROM `data` WHERE customerid={$id} AND id={$_POST[$i]}");
}
}
}
But
if(htmlspecialchars(trim($_POST["task".$i]))) {} is true for the deleted index
What is a possible solution to check, is element deleted or not?