Welcome Guest, Not a member yet? Register   Sign In
To connect to a database with controller
#5

[eluser]LuckyFella73[/eluser]
Here is (very basic) how you can insert form data into a database:
Code:
<?php

// place maybe in your constructor:
$this->load->model('your_model');


// Controller - after validation passed:
$db_data = array(
'title'  => $this->input->post('title'),
'text'  => $this->input->post('text'),
// ...

);

$this->your_model->add_entry($db_data);


// Model

class Your_model extends CI_Model
{
/**
  * The class constructer
  *
  */
public function __construct()
{
  parent::__construct();
}



/**
  * save data
  */
public function add_entry($data)
{
  if ($this->db->insert('db_table_name', $data))
  {
   return $this->db->insert_id();
  }
  else
  {
   return FALSE;
  }
}

Adjust $db_data coresponding to your table columns and input fields (name attr).


Messages In This Thread
To connect to a database with controller - by El Forum - 07-12-2012, 01:50 AM
To connect to a database with controller - by El Forum - 07-12-2012, 02:07 AM
To connect to a database with controller - by El Forum - 07-12-2012, 02:09 AM
To connect to a database with controller - by El Forum - 07-12-2012, 03:14 AM
To connect to a database with controller - by El Forum - 07-12-2012, 04:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB