I have a table filled with data from my database, and i want a button next to it for each specific user to delete that user. but how do i do this?
Here’s the code:
<?php
include '../includes/db_connect.php';
$sql = "SELECT * FROM `users`";
$result = mysql_query($sql, $connection) or die ("Failed to excecute the query $sql on $connection");
?>
<table border=1>
<tr>
<th>
Access lvl
</th>
<th>
Username
</th>
<th>
Email
</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
echo "</td><td>";
echo $row['access'];
echo "</td><td>";
echo $row['username'];
echo "</td><td>";
echo $row['email'];
echo "</td></tr>";
}
echo "</table>";
?>
I do this very often and use jQuery for it. I use the following:
HTML:
jQuery:
The
on()is for the dynamic elements (I do everything with AJAX on that page). Then I put the data I need to send in the correct format and do the AJAX request. In the PHP file could be this:Of course it’s recommended to use more checks to make sure you remove the right one.