Welcome Guest, Not a member yet? Register   Sign In
How record data using models?
#1

[eluser]8Lou[/eluser]
Hello folks, i trying to use codeigniter and models to add data to my database, but i cant, look my code and tell me whats wrong please

View/ index.php
Code:
<?php echo form_open('site/create');?>

<p>Nome
&lt;input type="text" name="nome" id="nome" size="20" /&gt;&lt;/p>
<p>Login
&lt;input type="text" name="login" id="login" size="20" /&gt;&lt;/p>
<p>Password
&lt;input type="password" name="senha" id="senha" size="20" /&gt;&lt;/p>
<p>Email
&lt;input type="text" name="email" id="email" size="20" /&gt;&lt;/p>
Status<br />
&lt;input type="radio" name="status" id="status" value="1" /&gt; Ativado<br />
&lt;input type="radio" name="status" id="status" value="0" /&gt; Desativado<br />
&lt;/form&gt;
<br />
&lt;input type="submit" value="Cadastrar" /&gt;
&lt;?php echo form_close(); ?&gt;

Controller/ site.php
Code:
class Site extends CI_Controller {

    function index()
    {    
        $this->load->view('admin/index');
    }
    
    function create ()
    {
        $data = array(
            'usr_nome' => $this->input->post('name'),
            'usr_login' => $this->input->post('login'),
            'usr_senha' => $this->input->post('senha'),
            'usr_email' => $this->input->post('email'),
            'usr_status' => $this->input->post('status')
        );
        
        $this->site_model->add_record($data);
        $this->index();
    }
}



Model/ model1.php
Code:
&lt;?php

class Model extends CI_Model {
    
    function __construct()
    {
            // Call the Model constructor
            parent::__construct();
    }
    
    function get_records()
    {
        $query = $this->db->get('user');
        return $query->result();
    }
    
    function add_record($data)
    {
        $this->db->insert('user', $data);
        return;
    }
    
    function update_record($data)
    {
        $this->db->where('user_id', 1);
        $this->db->update('user', $data);
    }
    
    function delete_row()
    {
        $this->db->where('user_id', $this->uri->segment(3));
        $this->db->delete('user');
    }
    
}

i've added database and activerecord to autoload
#2

[eluser]8Lou[/eluser]
sry, please delete it, wrong area




Theme © iAndrew 2016 - Forum software by © MyBB