I've been trying to delete a record in HTML/PHP but it didn't work and I've tried a lot. Does anyone know a solution for me?
<?php while($row=mysqli_fetch_assoc($result)){ ?>
<a href="delete.php?id=<?php echo $row['project_id']; ?>Delete</a>
<?php
}?>
And this is delete.php:
<?php
$id = $_GET['titel'];
$sql = "DELETE FROM Projects where titel= '".$id."'";
if(mysqli_query($dbLink,$sql)){
echo "<p>It is failed!</p>";
}
else{
echo "<p>Deleting is succesful done!</p>";}
?>
You're trying to $_GET['titel'];
but what you're meant to get is $_GET['id'];
Either change it to id
, or change your a
link to:
<a href="delete.php?titel=<?php echo $row['project_id']; ?>Delete</a>
What you should do then, in your delete.php
file, is change your $sql
to:
$sql = "DELETE FROM Projects where id= '".$id."'";
Also ensure $dbLink
is set in delete.php
.