I am trying to delete database entry with DELETE http request sent from axios in REACT.
function Delete() {
const form = new FormData();
for (var i = 0; i < selected.length; i++) {
form.append(i, selected[i]);
}
console.log(form)
axios.delete(url, form)
navigate(`/`)
}
As you can see here, I iterate over "selected" which is an array and assign keys in the form as numbers. For example first key in form is 1 with first "selected" value and so on. Then comes the PHP code.
header('Access-Control-Allow-Origin: http://localhost:3000');
header("Access-Control-Allow-Methods: GET, POST, DELETE");
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password, 'commerce');
$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case "DELETE":
parse_str(file_get_contents("php://input"), $_DELETE);
for ($i = 0; $_DELETE; $i++) {
$sku = $_DELETE[$i];
$delete = $conn->prepare("DELETE FROM baseinfos WHERE sku='$sku'");
$delete->execute();
}
break;
Here I am supposed to get the values of DELETE form, iterate over key values (which are numbers and iteration should work) and delete the corresponding entries in the database. Nothing happens, not even an error is thrown. What should I do?