Share via

Delete items from database in PHP

Jack Herer 140 Reputation points
2023-04-25T06:00:27.0566667+00:00
<?php

if (empty($_GET['id'])) {
    header('Location: index.php');
    die();
}

require_once 'db.php';

$sql = 'DELETE FROM cars WHERE id = :id';

$stmt = $conn->prepare($sql);
$stmt->execute([
    ':id' => $_GET['id'],
]);

header('Location: index.php');

?>
Community Center | Not monitored

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.