I'm trying to handle a query to delete multiple items with checkboxes. I'm using react for my frontend and php for my backend.
My frontend sends the payload form data like this : P.S My Primary Key is the SKU.
sku: DVD0004
sku: DVD0005
I need to combine these values into 1 bracket like this (DVD0004,DVD0005) in order to put them in my query which is
My API
public function deleteProduct($prdt_sku)
{
try {
$this->db->query("DELETE FROM products WHERE product_sku = :sku");
$this->db->bind(":sku", $prdt_sku);
if ($this->db->execute()) {
return true;
} else {
return false;
}
} catch (\Throwable) {
header("HTTP/1.1 406 Error deleting product from database");
}
}
*My actual form destination *
$response = array();
if (isset($_POST['sku'])) {
$sku = $_POST['sku'];
$result = $api->deleteProduct($sku);
if ($result) {
header("HTTP/1.1 200 OK");
header("Location: http://localhost:3000/");
exit();
} else {
header("HTTP/1.1 406 Error deleting product");
}
} else {
header("HTTP/1.1 499 Required parameters missing");
}