I'm trying to make a little control panel so I can add and delete rows in a database. I've already made the adding part work but I'm having some trouble with the deleting.
The page shows every row in a table and I've added a delete button behind it.
This are the codes I have
This is the code that makes the table:
<table class='col-sm-6 fixed_headers'>
<thead>
<tr>
<th>Username</th>
<th>Password</th>
<th>Email</th>
</tr>
</thead>
<tbody style='height:250px; overflow:auto;'>";
while($row = mysqli_fetch_array($result))
{
"<tr class=". $row['ID'] . ">";
echo "<td>" . $row['uname'] . "</td>";
echo "<td>" . $row['pass'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td><input type='submit' class='button' id=".$row['ID'] . " value='del'></td>";
echo "</tr>";
}
echo "</tbody>
</table>";
?>
Here is the ajax code:
<script type="text/javascript">
$(document).ready(function(){
$('.button').click(function(){
var btnID = $(this).id;
jQuery.ajax({
type: "POST",
url: "php/delete.php",
data: {id :btnID}
}).done(function(result){
if(result== "succes"){
$('#error').remove();
$('#succes').html("Het account is verwijderd. ");
}else {
$('#error').empty();
$('#error').html("Er is een fout opgetreden.<br/> Probeer opnieuw! ");
}
});
});
});
</script>
and here is the delete.php:
$id = mysql_real_escape_string($_POST['id']);
$delete = "DELETE FROM `xxx`.`xxx` WHERE `xxx`.`ID` = '$id'";
$del = mysql_query($delete);
if ($del)
{
echo "succes";
}
else
{
echo "error";
// close connection
mysql_close();
}
?>
when I press the delete button, I do get the succes message but the row hasn't been deleted of my database.
I have been trying to fix this, but I can't seem to make it work
(left out my db connect code)