spent long hours trying to add delete functionality to my to-do list. I can add todo to sql, also it apears on page, but cant find a way to delete my todo. Maybe someone can help me? here's the code:
<!DOCTYPE html>
<html>
<head>
<title>To Do</title>
</head>
<body>
<form action="index.php" method="post">
<input type="text" name="task" placeholder="New task"/>
<input type="submit" name="add" value="Add" autocomplete="off" required/>
</form>
<?php
if (isset($_POST['add'])) {
$sql = "INSERT INTO list (todo) VALUES ('$_POST[task]')";
$conn->query($sql);
}
if(isset($_POST['delete'])){
$sql ="DELETE FROM list WHERE todo={$_POST['todo']}";
$conn->query($sql);
}
$query = "SELECT * FROM list";
$result = mysqli_query($conn, $query);
?>
<?php
while ($row = mysqli_fetch_assoc($result)) { ?>
<?php echo $row['todo'] ?>
<form action='index.php?todo="<?php echo $row['todo']; ?>"'method="post">
<input type="hidden" name="todo" value="<?php echo $row['todo']; ?>">
<input type="submit" name="delete" value="Delete">
</form> <br>
<?php }
$conn->close();
?>
</body>
</html>