<?php
include ('../database/connect.php');
if(isset($_POST['delete'])) {
$id=$_GET['id'];
$delete = $con->prepare("DELETE FROM table WHERE id = '$id'");
header('location:student_add.php');
}
?>
<a class="btn btn-danger" href="#delete<?php echo $row['id']?>" data-toggle="modal">
<span class = "glyphicon glyphicon-trash" aria-hidden = "true"></span>
</a>
<!-- Modal -->
<div class="modal fade" id="delete<?php echo $row['id']?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-md">
<!-- Modal content-->
<div class="modal-content">
<div class="row">
<div class="col-lg-12">
<button type="button" class="close" data-dismiss="modal">×</button>
<section class="panel">
<header class="panel-heading">
Delete
</header>
</section>
</div>
</div>
<!------------Form Start------------->
<div class="modal-body">
<form action="delete.php" method="POST">
</div>
<!------------Entry Start------------->
<div class="modal-body">
<!------------ Name Start------------->
<div class="input-group">
<span class="input-group-addon"> Name:</span>
<div class="form-line">
<?php $row['id']; ?>
<?php echo $row['name']; ?>
</div>
</div>
<!------------ Name End------------->
<!------------Description Start------------->
<div class="input-group">
<span class="input-group-addon">Description:</span>
<div class="form-line">
<?php echo $row['description']; ?>
</div>
</div>
<!------------Description End------------->
</div>
<!------------Entry End------------->
<div class="modal-footer">
<button type="submit" class="btn btn-danger btn-lg" name = "delete">Delete</button>
</div>
</form>
<!------------Form End------------->
</div>
</div>
</div>
</div>
You have to execute it. You also should be properly binding the parameters instead of passing the literal variable into your statement since you are using prepared statements.
Why?
- To prevent people deleting your complete database
How?
- Easy, just as that
$delete = $con->prepare("DELETE FROM table WHERE id = ?"); $delete->execute([$id]);
I want to delete id but it doesn’t work and why? Where is the problem in my code?
What don’;t you understand about @spaceshiptrooper and @chorn;s posts?
The posts mentioned that the script is only being prepared and awaits an execute command.
It would be as well to check if the execute is successful rather than just calling header(…);
1 Like
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.