How to insert data into database in CodeIgniter – [Example]
Published 03/10/2021 16:13 | CodeIgniter |Here we discuss how to Insert Post data in to the database with example code in CodeIgniter. This code you can use In your project to insert data in the MySQL database. All data submission projects must need MySQL query to submit it.
In this example we are going to describe and how you can create a table in data base. Read and apply the below code for insert code.
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
First of all, you need to create a table in Codeigniter insert data into database SQL so use this query:
CREATE TABLE crud (
`id` int(11) AUTO_INCREMENT PRIMARY KEY NOT NULL,
`first_name` varchar(30) NOT NULL,
`last_name` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL
);
In this project we use 3 types of files for data in MySQL:
- Crud.php Path: codeIgniter\application\controllers\Crud.php
- Crud_model.php Path: codeIgniter\application\models\Crud_model.php
- insert.php Path: codeIgniter\application\views\insert.php
Crud.php (Controller)
After doing all steps need to run the program using URL: