Posted on 2018-10-12 19:09:33
Download Source Code / FileThis is the easiest way to insert data into the mysql database in codeigniter. If you need to download the source code click on the Download button.
***view***
<form action="<?= base_url()?>admin/add_data_into_db" method="post">
<input type="text" name="name" placeholder="name">
<input type="email" name="email" placeholder="email">
<input type="text" name="tp" placeholder="telephone">
<input type="submit" value="submit">
</form>
***controller***
class admin extends ci_controller {
function __construct() {
parent::__construct();
}
public function add_data() {
$this->load->view('add_data');
}
public function add_data_into_db() {
$data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'tp' => $this->input->post('tp')
);
// $data = $this->input->post();
$this->load->model('admin_model');
$this->admin_model->add_data($data);
echo 'successfuly added to the database';
}
}
***model***
class admin_model extends ci_model {
public function __construct() {
parent::__construct();
}
function add_data($data) {
$this->db->insert('user', $data);
}
}