metodo delete per eliminare un record nel database (parte 140)
| | |
| | | public function delete(string $id) { |
| | | $product = $this->getProduct($id); |
| | | |
| | | if($_SERVER["REQUEST_METHOD"] === "POST") { |
| | | $this->model->delete($id); |
| | | header("Location: /products/index"); |
| | | exit; |
| | | } |
| | | |
| | | echo $this->viewer->render("shared/header.php", [ |
| | | "title" => "Delete Product" |
| | | ]); |
| | |
| | | |
| | | return $stmt->execute(); |
| | | } |
| | | |
| | | public function delete(string $id): bool { |
| | | $sql = "DELETE FROM {$this->getTable()} WHERE id = :id"; |
| | | |
| | | $conn = $this->database->getConnection(); |
| | | $stmt = $conn->prepare($sql); |
| | | $stmt->bindValue(":id", $id, PDO::PARAM_INT); |
| | | |
| | | return $stmt->execute(); |
| | | } |
| | | |
| | | |
| | | ?> |
| | | } |