Posted inProgramming / Codeigniter / Mysql / Mysqli / php

CodeIgniter Insert Records into MySQL database Example

Today, We want to share with you CodeIgniter Insert Records into MySQL database Example.In this post we will show you insert form data into database using CodeIgniter, hear for how to insert data in database using model in CodeIgniter we will give you demo and example for implement.In this post, we will learn about how to insert post data in to database with example code in codeigniter with an example.

CodeIgniter Insert Records into MySQL database Example

There are the Following The simple About CodeIgniter Insert Records into MySQL database Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop php – insert data into database with codeigniter, so CodeIgniter save form data to database for this example is following below.

Step 1 : Import MySQL Table into your database

Create a member table schema

CREATE TABLE `members_tbl` (
  `id` int(10) UNSIGNED NOT NULL,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `member_phone` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `member_cmnt` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
ALTER TABLE `members_tbl`
  ADD PRIMARY KEY (`id`);
 
ALTER TABLE `members_tbl`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;COMMIT;

Step 2: CodeIgniter View Files

application/views/member_form.php


uri->uri_string()); ?> 'memberfname', 'name' => 'memberfname' )); ?> 'email', 'name' => 'email' )); ?> 'member_phone', 'name' => 'member_phone' )); ?> 'member_cmnt', 'name' => 'member_cmnt' )); ?> 'submit', 'value' => 'Submit' )); ?>

Setp 3 : Create a controllers in CodeIgniter

application/controllers/Member.php

load->model('member_model');
        $this->load->model(array('form','url','html'));
        $this->load->databae();
    }
 
    function index() {
 
        $this->load->library('form_validation');
        $this->form_validation->set_error_delimiters('
', '
'); $this->form_validation->set_rules('memberfname', 'Member First Name', 'required|min_length[5]|max_length[15]'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); $this->form_validation->set_rules('member_phone', 'Phone Number', 'required|regex_match[/^[0-9]{10}$/]'); $this->form_validation->set_rules('member_cmnt', 'Comments', 'required|min_length[10]|max_length[50]'); if ($this->form_validation->run() == FALSE) { $this->load->view('member_form'); } else { $membersdata = array( 'memberfname' => $this->input->post('memberfname'), 'email' => $this->input->post('email'), 'member_phone' => $this->input->post('member_phone'), 'member_cmnt' => $this->input->post('member_cmnt') ); $this->insert_model->form_insert($membersdata); $this->load->view('member_form', $membersdata); } } } ?>

Setp 4 : Create a Model in CodeIgniter

application/models/Member_model.php

table = 'members_tbl';
        }
        function form_insert($data){
            $this->db->insert($this->table, $data);
        }
    }
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about CodeIgniter Insert Records into MySQL database Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype