I am building a PHP & mySQLi CRUD app.
Inside a functions.php file I have a function that takes care of deleting individual users:
function delte_single_user() {
if (isset($_GET['id'])) {
global $con;
$user_id = $_GET['id'];
$sql = "DELETE * FROM `users` WHERE `id`= " . (int)$user_id . ";";
$result=mysqli_query($mysqli, $sql);
}
}
In the file that displays the users, I have the CRUD "buttons":
<ul class="list-inline">
<li><a title="View user" href="view_user.php?id=<?php echo $arr['id']; ?>"><span class="glyphicon glyphicon-user"></span></a></li>
<li><a title="Delete user" onclick="delte_single_user()"><span class="glyphicon glyphicon-trash"></span></a></li>
</ul>
As you can see, I am trying to fire the delte_single_user()
upon clicking the delete button, JavaScript style (I am new to PHP but I have significant experience JavaScript). But it does not work.
So, what is PHP's closest alternative to my use of delte_single_user()
?
NOTE: I am trying to avoid creating a delete_user.php fie as it would not be useful.
Thank you!