6. Data Delete

1.Method
obviously have to put this code in fresh.php. where have your database connect.

/* Data Delete */
    
    public function Delete($table,$id){
        $query = mysqli_query($this->connect,"DELETE FROM $table WHERE id=$id");
        if(mysqli_affected_rows($this->connect)>0){
            return true;
        } else{
            return false;
        }
    }

2.tabulize_data.php

<?php
include("fresh.php");
if (isset($_REQUEST['id'])) {
    /* The isset () used to check whether a variable is set or not.
       If a variable is already unset.The isset() return false.
     */
    //super global variable $_REQUEST uses to collect the value of the input field:
    if ($obj->Delete("members", $_REQUEST['id'])) {
        $err_msg = "Successfully Deleted";
    } else {
        $err_msg = "No Data Delete";
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Show Database</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    </head>

    <body>
        <div style="width: 800px; margin: 0 auto">
            <?php
            echo (isset($err_msg)) ? $err_msg : "";
            ?>
            <table class="table table-bordered table-hover" style="text-align: center;">
                <tr>
                    <td>Id</td>
                    <td>Name</td>
                    <td>E-mail</td>
                    <td>Phone</td>
                    <td>Address</td>
                    <td>Action</td>
                </tr>
                <?php
                $team = $obj->getData("members");
                //print_r($team);
                foreach ($team as $single) {
                    extract($single);
                    ?>   
                    <tr>
                        <td><?php echo $id; ?></td>
                        <td><?php echo $name; ?></td>
                        <td><?php echo $email; ?></td>
                        <td><?php echo $phone; ?></td>
                        <td><?php echo $address; ?></td>
                        <td><a href="edit.php?id=<?php echo $id; ?>" class="btn btn-primary"><span class="glyphicon glyphicon-pencil"></span></a>&nbsp;<a href="tabulize_data.php?id=<?php echo $id; ?>" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a></td>
                    </tr>
                    <?php
                }
                ?>
                <td colspan="6" align="right"><a class="btn btn-info" href="insert.php">Add New Member</a></td>
            </table>
        </div>
    </body>
</html>

Output following screenshot:
Delete

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s