Welcome Guest, Not a member yet? Register   Sign In
Can't insert new record to MySQL Database
#1

[eluser]Unknown[/eluser]
hello guys,
i'm kinda new to CI so can't use it properly even for a simple matter like insert new record..

please don't order me to googling because I already did it first and still stuck

and sorry for bad english..

so this is the MVC of mine

Model
Code:
<?php
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Test_model extends CI_Model{
        public function insert($data){
            return $this->db->insert_string('testinsert', $data);
        }
    }
?>

Control
Code:
<?php
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Test_controller extends CI_Controller{
        function __construct() {
            parent::__construct();
            $this->load->model('test_model', '', true);
        }
        
        public function index(){
            $this->load->view('test_view');
        }
        
        public function inserts(){
            $this->form_validation->set_rules('id', 'ID', 'trim|required');
            $this->form_validatoin->set_rules('deskripsi', 'DESKRIPSI', 'trim|required');
            
            $data = array('id'=> $this->input->post('id'), 'deskripsi'=>$this->input->post('deskripsi'));
            
            $st = $this->test_model->insert($data);
            echo $st;
        }
    }
?>

View
Code:
<!DOCTYPE HTML>
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Test Insert&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;?php echo validation_errors(); ?&gt;
        &lt;?php echo form_open('test_controller'); ?&gt;
        <table>
            <tr>
                <td>id</td>
                <td>:</td>
                <td>&lt;input type="text" name="id" /&gt;&lt;/td>
            </tr>
            <tr>
                <td>deskripsi</td>
                <td>:</td>
                <td>&lt;input type="text" name="deskripsi" /&gt;&lt;/td>
            </tr>
            <tr>
                <td colspan="2">&lt;input type="submit" value="Submit" /&gt;&lt;/td>
            </tr>
        </table>
    &lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
Can't insert new record to MySQL Database - by El Forum - 07-03-2013, 09:59 PM
Can't insert new record to MySQL Database - by El Forum - 07-03-2013, 11:39 PM
Can't insert new record to MySQL Database - by El Forum - 07-04-2013, 12:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB