When you start the project with Codeigniter framework then you need to insert data into the database. Insert a record in MySQL table using CodeIgniter framework.
At first, you need to connect database in your project file and then create form page where you create an insert form or signup form. Put a action in the form and go to the controller page and call the function and set the form value in an array variable. Then connect the Model page in the controller page and define a function in controller page for pass data into the Model page.
Now go to the model Page and call the function name and write the right MySQL query for insert data into the database.
Database connection:
Application folder -> Config -> database.php 'hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'my_db', 'dbdriver' => 'mysqli'
Form Page:
Application -> views -> form.php
Create form using codeigniter code.
<?php $fcl=array('class'=>'smart-wizard','id'=>'form'); echo form_open_multipart('Welcome/user_registration',$fcl); ?> <input type="text" class="form-control" name="name"/> <input type="email" class="form-control" name="email"/> <input type="password" class="form-control" name="pwd"/> <?php echo form_close(); ?>
Controller:
Application -> Controllers ->Welcome.php
class YesuusMainController extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->helper('form'); $this->load->database(); $this->load->model('Mymodel'); } public function user_registration(){ $data = array('name' => $this->input->post('name'),'email' => $this->input->post('email'),'password' => $this->input->post('pwd')); $this->Mymodel->UserRegistration($data); } }
Models:
Application -> Models -> Mymodel.php
class Mymodel extends CI_Model{ Public function UserRegistration($data){ $query=$this->db->insert('Table Name',$data); } }
Click Here: To Get Code of Select and fetch records from the database in CODEIGNITER
If you want to insert user records into the database using jQuery in you Codeigniter then click here Submit all records into MySQL table without page reload.
Create a Live search like google using PHP-Codeigniter, jQuery & MySQL. I hope it will be most helpful for you