I'm quite new to PHP and I'm trying to make a basic CRUD with PHP. I'm able to add the record and display it in a table with two actions button on the same row. However, I cannot delete the record from the database and make the table updated (with the data removed). When I hover my mouse on the delete button, it seems like the variable is being parsed but when I clicked on the delete button it says URL not found. I've included some of my code below. Thanks in advance.
The table that shows all the records from the data base:
<div class="form-group">
<table class='table'>
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Gender</th>
<th>Location</th>
<th colspan="2">Action</th>
</tr>
</thead>
<?php
$result = $conn->query('SELECT * FROM tb_user ORDER BY id DESC') or die($conn->error);
while($row = $result->fetch_object()):?>
<tr>
<td><?php echo $row->first_name; ?> </td>
<td><?php echo $row->last_name; ?></td>
<td><?php echo $row->gender; ?></td>
<td><?php echo $row->place; ?></td>
<td colspan="2">
<a href="index.php?edit<?php echo $row->id; ?>" class="btn btn-info">Edit</a>
<a href="process.php?delete=<?php echo $row->id; ?>" class="btn btn-danger">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
Here's the "Delete" code:
if(isset($_GET['delete'])){
$uId = $_GET['delete'];
$sql = "DELETE FROM tb_user WHERE id = $uId";
$conn->query($sql);
$_SESSION['message'] = "Record has been deleted!";
$_SESSION['msg_type'] = "danger";
header("location: index.php");
}
I'm able to get to a blank page with a correct URL instead of getting an "URL not found" error.
The problem was my process.php
file wasn't in the same directory as my index.php
file.