I want to delete the row in database that has the text output using the button right next to the text. So here is my code:
<?php
...
while ($finresult = mysqli_fetch_array($result)){
if ($finresult['id'] == $id){
print_r($finresult['email']);
$print = $finresult['email'];
echo '<p id="demo"> </p><button onclick="getElementById(\'demo\').innerHTML=myajax($print)">Delete</button>
';
?>
<html>
<script>
function myajax(id){
$.ajax({
type: "POST",
url: "delete.php",
data: id
success: function(data){
if (data == id + "y"){
return "It works";
}
else{
return "Doesn't work";
}
}
});
}
</script>
</html>
This is the delete.php
<?php
$link = mysqli_connect("localhost","*****","****");
mysqli_select_db($link, 'form');
$id = $_POST['id'];
$query = "DELETE FROM Customers WHERE Customers.email = '$id'";
$result = mysqli_query($link, $query);
if (isset($result)){
echo "y";
}
else{
echo "n";
}
?>
I would really appreciate if someone could tell me what is going wrong. Thanks!