CodeIgniter - Form: Creating Insert Data

CodeIgniter Form Step By Step Tutorial - Part 12: We have had a form and a table. Now, we build function for insert data.

First, update our controller, books.php within controller folder.Add line 21,22,23 like below:

class Books extends Controller{

  function Books(){
  function main(){
	$data = $this->books_model->general();
  function input(){

	$data = $this->books_model->general();

If someone click submit button, we will call entry_insert() from model books.

Ok, now, update our model books_model.php within models folder. Add a method named entry_insert() like below:

class books_model extends Model{
  function books_model(){
  function entry_insert(){
	$data = array(
  function general(){
	$menu = new MyMenu;
	$data['base']		= $this->config->item('base_url');
	$data['css']		= $this->config->item('css');		
	$data['menu'] 		= $menu->show_menu();
	$data['webtitle']	= 'Book Collection';
	$data['websubtitle']= 'We collect all title of 
		                   books on the world';
	$data['webfooter']	= '© copyright by step 
		                   by step php tutorial';
	$data['title']	 	= 'Title';
	$data['author']	 	= 'Author';
	$data['publisher']	= 'Publisher';				
	$data['year']	 	= 'Year';
	$data['years']	 	= array('2007'=>'2007',
	$data['available']	= 'Available';	
	$data['summary']	= 'Summary';
	$data['forminput']	= 'Form Input';
	$data['ftitle']		= array('name'=>'title',
	$data['fauthor']	= array('name'=>'author',
	$data['fpublisher']	= array('name'=>'publisher',
    $data['favailable']	= array('name'=>'available',
	$data['fsummary']	= array('name'=>'summary',
	return $data;	

Ok. You can test it. Input some data from input form.

Series this article:
CodeIgniter - Form: Creating Skeleton
CodeIgniter - Form: File Structure
CodeIgniter - Form: Creating Layout Code
CodeIgniter - Form: Creating Menu Library
CodeIgniter - Form: Putting Text at Header and Footer
CodeIgniter - Form: Centralizing $data
CodeIgniter - Form: Adding CSS
CodeIgniter - Form: Creating Form HTML
CodeIgniter - Form: Creating Beautiful Form Code
CodeIgniter - Form: CodeIgniter HTML Style
CodeIgniter - Form: Preparing Table at Database
CodeIgniter - Form: Creating Insert Data
CodeIgniter - Form: Creating List Data Use Table Library
CodeIgniter - Form: Creating Table List Without Table Library
CodeIgniter - Form: Using URL Helper
CodeIgniter - Form: Showing Single Data for Form Edit
CodeIgniter - Form: Something Happen With Form Parameters
CodeIgniter - Form: Updating Data
CodeIgniter - Form: Deleting Data

Bookmark and Share Tag: CodeIgniter, framework, MVC, database, insert, put Category: PHP Framework Post : February 25th 2008 Read: 217,357


blog comments powered by Disqus