so I am very new with php technology and I am trying to display a database and be able to delete some of the rows. I have tried this code but It doesn't work as intended. I have made the conexion with mySQL database and the GET Request works but I don't get why this DELETE request doesn't.
<!DOCTYPE html>
<html lang="EN">
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8' />
<title> My database </title>
<script>
function removeSelectedEmails(){
var aux = "";
for (x in selectedEmails) {
if(x== 0) {aux += "?email[]=" + selectedEmails[x];}
else {aux += "email[]=" + selectedEmails[x];}
if(selectedEmails[x] != selectedEmails.slice(-1)[0]) {
aux += "&";
}
var xmlhttp2 = new XMLHttpRequest();
xmlhttp2.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
showEmails(last_q);
}
};
xmlhttp2.open("DELETE","db.php" + aux,true);
xmlhttp2.send();
}
</script>
<body>
<?php
if($_SERVER['REQUEST_METHOD'] === 'DELETE') {
$query = "DELETE FROM emails WHERE email=" . $value;
if ($conn->query($query) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
}
?>
</body>
</html>
It seems like it not executing the PHP part but the JS is working fine and I copy paste the GET request that is working and just change the "GET" to "DELETE" and stop working. Thank you in advance for the help.