To do this first just create database tablecrud and then create table as posts and then create columns post_id ,post_title,image_title and post_image as integer,varchar,varchar and varchar respectively..
First, create db.php file for database connection as
- <?php
- //this scripts connect to your database
- $db_host = "localhost";
- $db_name = "tablecrud";
- $db_user = "root";
- $db_pass = "";
- try{
- $db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
- $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e){
- echo $e->getMessage();
- }
- ?>
Now, create index.php file write some php pdo scripts as this and also create form as this below of index.php file
- <!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> How to delete Images of a folder permanently.</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
- <script src="../js/jquery.min.js"></script>
- <script src="../bootstrap/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container">
- <div class="thumbnail">
- <h4 style="color:#F06"> Add, Edit ,Delete and Display using php pdo and bootstrap.</h4>
- <form method="post" action="upload.php" enctype="multipart/form-data">
- <table class="table1">
- <tr>
- <td><label style="color:#3a87ad; font-size:18px;" > Title</label></td>
- <td width="30"></td>
- <td><input type="text" name="post_title" placeholder="title" class="form-control" required /></td>
- </tr>
- <tr>
- <td><label style="color:#3a87ad; font-size:18px;">Image Title</label></td>
- <td width="30"></td>
- <td><input type="text" name="image_title" placeholder="image_title" class="form-control" required /></td>
- </tr>
- <tr>
- <td><label style="color:#3a87ad; font-size:18px;">Select Image</label></td>
- <td width="30"></td>
- <td><input type="file" name="image"></td>
- </tr>
- </table>
- <button type="submit" name="Submit" class="btn btn-success">Submit</button>
- </form>
- </div>
- <table class="table table-striped">
- <thead>
- <tr>
- <th>Title</th>
- <th>Image Title</th>
- <th>Images</th>
- <th>Delete</th>
- <th>Update</th>
- </tr>
- </thead>
- <?php
- include('db.php');
- //query for selecting database table
- $results = $db_con->prepare("SELECT * FROM posts ORDER BY post_id");
- $results->execute();
- // this while statement displays rows of database table
- while($row=$results->fetch(PDO::FETCH_ASSOC))
- {
- extract($row);
- ?>
- <tbody>
- <tr>
- <td><?php echo $row['post_title']; ?></td>
- <td><?php echo $row['image_title']; ?></td>
- <td><img src="uploads/<?php echo $row['post_image']; ?>" class="img-rounded" alt="image" style="width:60px" height="60px;">
- </td>
- <td> <a href="editform.php?id=<?php echo $row['post_id'];?>" class="btn btn-info">Update</a></td>
- <td><a href="delete.php?post_id=<?php echo $post_id; ?>" class="btn btn-danger">Delete</a> </td>
- </tr>
- </tbody>
- <?php
- }
- ?>
- </table>
- </div>
- </body>
- </html>
No comments:
Post a Comment