PDO Connectivity Step 5

PDO Connectivity Step 5

5. Delete Data

<?php
// include database connection file
require_once 'dbconfig.php';
$database = new Connection();
$db = $database->openConnection();

// Code for record deletion
if (isset($_REQUEST['del'])) {
//Get row id
    $uid = intval($_GET['del']);
//Qyery for deletion
    $sql = "delete from pdo_practice WHERE  id=:id";
// Prepare query for execution
    $query = $db->prepare($sql);
// bind the parameters
    $query->bindParam(':id', $uid, PDO::PARAM_STR);
// Query Execution
    $query->execute();
// Mesage after updation
    echo "<script>alert('Record Deleted successfully');</script>";
// Code for redirection
    echo "<script>window.location.href='index.php'</script>";
}

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*