insert and display data from database in codeigniter

Today, We want to share with you insert data in codeigniter.In this post we will show you codeigniter migration inserts data, hear for add data in database in codeigniter we will give you demo and example for implement.In this post, we will learn about How To Insert Data Into Database With CodeIgniter? with an example.

How to insert data in database – CodeIgniter framework

SQL Query

  `id` int(11) NOT NULL,
  `first_name` varchar(30) NOT NULL,
  `last_name` varchar(30) NOT NULL,
  `email` varchar(30) NOT NULL,

Crud.php (Controller)

class Crud extends CI_Controller 
	public function __construct()
	/*call CodeIgniter's default Constructor*/
	/*load database libray manually*/
	/*load Model*/
	public function storememberinfo()
		/*load registration view form*/
		/*Check submit button */
			        echo "Records Saved Successfully";
					echo "Insert error !";

Crud_model.php (Model)

class Crud_model extends CI_Model 
	function saverecords($data)
          return $this->db->insert_id();

insert.php (View)

<!DOCTYPE html>  
<title>Registration form</title>
	<form method="post">
		<table width="600" border="1" cellspacing="5" cellpadding="5">
    <td width="230">First Name </td>
    <td width="329"><input type="text" name="first_name"/></td>
    <td>Last Name </td>
    <td><input type="text" name="last_name"/></td>
    <td>Email ID </td>
    <td><input type="email" name="email"/></td>
    <td colspan="2" align="center"><input type="submit" name="save" value="Save Data"/></td>

Run the program on your browser with URL:


I hope you get an idea about insert data in codeigniter.
I would like to have feedback on my 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.