Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Inserting Form values into mysql database using codeigniter [closed]

I am new to the Codeigniter.How to store the form values in mysql using codeigniter ,Can any one help me...Is there any links Can you provide.... Thanks In Advance.

like image 651
Naveen Avatar asked Dec 07 '22 14:12

Naveen


2 Answers

Let me clearify you in an easy way...

This will be your controller

class Site extends CI_Controller
{
function index()
{
$this->load->view('form.php');// loading form view
}

function insert_to_db()
{
$this->load->model('site_model');
$this->site_model->insert_to_db();
$this->load->view('success');//loading success view
}
}

This will be your views. Befor creating views go to autoload.php and autoload url helper and database class. In your config.php set config['base_url'] = "path to your site"; form.php

<form action="<?php echo base_url();?>index.php/site/insert_into_db" method="post">
Field 1 = <input type = 'text' name='f1'>
Field 2 = <input type = 'text' name='f2'>
Field 3 = <input type = 'text' name='f3'>
<input type='submit'>
</form>

success.php

<b>Your data has been inserted!!!</b>

In your model you need to pull those datas of form and insert into db this way

site_model.php

class Site_model extends CI_Model
{
function insert_into_db()
{
$f1 = $_POST['f1'];
$f2 = $_POST['f2'];
$f3 = $_POST['f3'];
$this->db->query("INSERT INTO tbl_name VALUES('$f1','$f2','$f3')");
}
}

In this case your database has three fields... modify query as per your requirements

like image 94
Anwar Avatar answered Dec 10 '22 11:12

Anwar


The CodeIgniter manual is pretty helpful.

Take a look at the Database Quickstart.

like image 21
Jeremy Lawson Avatar answered Dec 10 '22 12:12

Jeremy Lawson