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.
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
The CodeIgniter manual is pretty helpful.
Take a look at the Database Quickstart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With