Simple CRUD Apps With Codeigniter Tutorial For Beginners

Continuing my two previous CodeIgniter tutorial articles. On this occasion, I will discuss how to create a simple CRUD application using CodeIgniter framework for beginners. Codeigniter is a PHP framework that is suitable for beginner. All libraries for develop application have been provided by CodeIgniter. The concept of MVC on CodeIgniter allows a beginner to code neatly and regularly. Follow the following tutorial.

In the previous article, I have discussed the basic knowledge of what is CodeIgniter and MVC concept on CodeIgniter. If you are a beginner who learning about this PHP framework, it’s good first to read my previous article to follow this article correctly.

To understand more detail our CodeIgniter tutorial, we will make a simple CRUD application to display product list, add, edit and delete data in the product database. In this CodeIgniter tutorial, will be divided into several step like the following table of contents.

Codeigniter tutorial for beginners step by step

Installing Codeigniter

I have discussed in full how to install CodeIgniter in the article “Introduction – PHP Codeigniter Tutorial For Dummies Step By Step.” Please download Master CodeIgniter on the official site. Then extract and create a new project named mycodeigniter.

Next step we will do the basic configuration of CodeIgniter. Please open the config.php file in the “application/config” folder and do the settings according to the following script:

Make sure the installation has been successful and run the URL http://localhost/mycodeigniter like the following picture below:

PHP Codeigniter Tutorial Installation Successfull

Configure MYSQL database on CodeIgniter using PDO – Codeigniter Tutorial

Next, we will tell the CodeIgniter about what libraries we need during the development process. This configuration contained in the autoload.php file in the “application/config folder”.

How to connect CodeIgniter and MySQL using PDO is quite easy. You just need to add the following settings to the database.php file in the folder (application/config/database.php).

Create database “pos” in MySQL and add data in the product table

Create a new database with the name “pos.” Then create a new table with the name “m_item” with fields like the following picture:

Create Pos Database Mysql And M Item table

Add 2 data in the “m_item” table with the following MySQL script:

Displays the product list

To interact with the product table we have to create a new model stored in the “application/model” folder, and please create a model with the name Product_model.php then type the following script

When finished creating the model then the next step, we will create a controller that will connect to the model and view, the controller will be stored in the “application/controller” folder. Create a new controller named Product.php and write the following script:

Now that the model and controller is done, the final step is to build a view to display the data to the application user, and this view is stored in the “application/view” folder. Create a view with the name of product_list.php and type the following script:

Please try at your browser with url: http://localhost/mycodeigniter/index.php/product/

If successful then the system will display the product list as shown below.

Create Crud Codeigniter Tutorial How To Display List Item Min

Create a new product

The data-added process requires two functions on the controller:

add function:
The task is to invoke the view to display the input form.

save function:
The task is to store data inputted by the user and submitted to the model to saved in the database

Add the following script to the Product.php controller:

To communicate with the database, create new function in the product_model.php to save new data to “m_item” table.

Up to this point, the display of our application will be as follows:

Codeigniter Tutorial How To Add New Item Result

Update item data

The two processes will be discussed at this step is the process of retrieve data from the database and update process to change the existing records.

Like my previous CRUD tutorial, where the user will select the product to be edited. Then customize the product with the new data and then the save process will update the database.

The update process requires two functions on the controller product:
edit function:
Used to display the edit product form

save_edit function:
This function stores the result of data changes and passes it to the model to update the items in the database.

Copy the following script to create update controller:

Create a new view as product_edit.php to display the edit form. Copy the following script to product_edit.php

Create update function on Product_model.php  to update data in the database:

The next step is edit your product_list.php view and add the following script:


Anchor is a function in the helper URL in Codeigniter  library used to create a link.

Until  this step the display of our application as shown below:

Codeigniter Tutorial How To Update The Item Result

Delete product data

In the last section of this CodeIgniter tutorial, I will explain how the process of deleting data from the database.

To delete the data just needed one function on the controller and one function on the model. Please copy the script below to the Product.php controller:

And please copy the script below and paste in the Product_model.php

The last step is create anchor to execute the delete function, please add the following script to product_list.php view.

Please save and run the application in your browser.

Codeigniter Tutorial How To Create Delete Function To Delete Record Of Table In Mysql Database

Up to this point, the CodeIgniter tutorial for beginners with CRUD examples has been completed. If you have some advice or want to ask question for me, please fill the comment form below.

To download the entire project please use the following url:


Thus my article about tutorial how to create simple CRUD apps with codeigniter for beginner, hope useful.

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.


 Add your comment
  1. Hi,

    Where’s your code and form for the “Add New Product”?


  2. what’s the password

  3. Excelent tutorial!!..

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.