June 30, 2014 10:51 am

PHP CRUD with Twitter Bootstrap 3 Part – 2/2

PHP CRUD This is the 2nd part of CRUD tutorial in this part we will cover “Read“, “Update” and “Delete“options in our previously created grid in tutorial part 1. I will give you its complete demo and a source code to download free so you can try that in your own websites.

PHP CRUD with Twitter Bootstrap Part - 2

Read: PHP CRUD with Twitter Bootstrap 3 Part – 1/2

We have already created create option in our previous part after adding a record our grid looks like this:

PHP CRUD Main page part 2

Create Read page

Create a page “read.php” and add in your CRUD directory, this file used to give read functionality to you CRUD system.

Above section contains PHP code on top is used to get id of record from query string and pass that id to database and get users information. If id not passed in query string then it will be redirected to “index.php” page and if invalid id passed in that case it will again redirect to “index.php” page.

Passing a valid id to the read page it will fetch data in $data variable and put it in 2nd part of the page which is HTML and make it view able to you.

PHP CRUD Read page

Create Update page

Create a PHP page for update data “update.php”. This is the update part of CRUD system, as we have already created Create file we use the same file to build form and use PHP of Read form to get data on based of id and make update query.

This code is used to Update a user’s data and its a combined page of Create and Read with the change in query like in create page we used to insert data and here in update page that same query changed to update. Read code of PHP is used to fetch data from table and put in form input fields.

When you post data it will validate data in PHP if data validated successfully the run update query and update your data.

PHP CRUD Update page

Now we have to do final step of PHP CRUD.

Delete Page

Create a page to delete data to do that we have created a file “delete.php” in that file we put below code in our file and add a button in out main page for delete.

The delete page code first of all comes to “delete.php” page and confirm that you want to delete that record with an id in query string. If id not passed in query string then it will be redirected to “index.php” page if id exists it will ask for confirmation with yes and no buttons if you press yes it will delete record and redirect to “index.php” page if you press no it will redirect to “index.php” page without deleting the record.

PHP CRUD Delete page

Finally our PHP CRUD grid looks like this:

PHP CRUD Main page complete

That’s all for PHP CRUD I hope you enjoyed this tutorial and find it helpful. If you have any question or suggestion please feel free  to comment below. Do share this with your using below social buttons.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.


Tutorial Categories:
  • ashington

    This is a really nice code, its easier to understand and use

  • good post. code is easy to understand

  • sak chai

    good post. if can use pagination and searching. it very goood

  • Afdoal Wahyurrahman

    how show delete confirm in modal window?? (not in other page)

    thanks b4

    • Nilesh Daldra

      for showing model window you have to use bootstrap window model.

  • Its really good
    i suggest make it – SEO friendly
    Add Custom SLUG/META TAGS field http://www.phpgang.com/how-to-rewrite-urls-with-htaccess_477.html

    Please guide me http://localhost/php-curd/read.php?id=1 to http://localhost/php-curd/huzoor
    If possible please update PART-3 with these updates also add CURD AJAX without refresh content saved/delete/create

  • pawan parajapat

    Huzoor Bux is Great Author for web development coding.

    this script you post that very helpful for me
    thank you Huzoor Bux

  • adminawala

    how to add search function mr huzoor bux ?

  • Vip3r011

    thanx

  • Thank you very much for this nice tutorial. I have download script and test all action (create, read, update, delete), it work fine without any error.