[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
<input type="text" name="nome" id="nome" size="20" /></p>
<p>Login
<input type="text" name="login" id="login" size="20" /></p>
<p>Password
<input type="password" name="senha" id="senha" size="20" /></p>
<p>Email
<input type="text" name="email" id="email" size="20" /></p>
Status<br />
<input type="radio" name="status" id="status" value="1" /> Ativado<br />
<input type="radio" name="status" id="status" value="0" /> Desativado<br />
</form>
<br />
<input type="submit" value="Cadastrar" />
<?php echo form_close(); ?>
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:
<?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