[PHP] CRUD Menggunakan PDO [Bagian 5]
Lanjutan dari [PHP] CRUD Menggunakan PDO [Bagian 4]
DELETE data
Selanjutnya source code untuk menghapus data.
Buat file bukutelp_delete.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?php include "connect_db.php"; try { // delete query $query = "DELETE FROM buku_telp WHERE id = ?"; $stmt = $con->prepare($query); $stmt->bindParam(1, $_GET['id']); if($stmt->execute()){ echo "Sukses menghapus data <br /> <a href="bukutelp_view.php">Lihat Buku Telepon</a>"; }else{ die('Gagal menghapus data.'); } } // to handle error catch(PDOException $exception){ echo "Error: " . $exception->getMessage(); } ?> |
Referensi :
codeofaninja.com
php.net – pdostatement
php.net – migration55
phpro.org