[eluser]terry101[/eluser]
Hey i am working on building a register form but having trouble inserting into my database.
I am getting a error on line 37 on my controller (placed a star on line 37 in here). Anyone know where i went wrong?
error i'm getting
! ) Fatal error: Call to a member function register_user() on a non-object in C:\wamp\www\code\application\controllers\user.php on line 37
View
<html>
<head>
<title> Regristration form</title>
</head>
<body>
<h1>User Registration</h1>
<p>Please fill in the details below</p>
<?php
echo form_open($base_url . 'user/register');
$username = array(
'name' => 'username',
'id' => 'username',
'value' => set_value('username')
);
$name = array(
'name' => 'name',
'id' => 'name',
'value' => set_value('name')
);
$email = array(
'name' => 'email',
'id' => 'email',
'value' => set_value('email')
);
$password = array(
'name' => 'password',
'id' => 'password',
'value' => ''
);
$password_conf = array(
'name' => 'password_conf',
'id' => 'password_conf',
'value' => ''
);
?>
<ul>
<li>
<lable> Username</lable>
<div>
<?php echo form_input($username);?>
</div>
</li>
<li>
<lable> Name</lable>
<div>
<?php echo form_input($name);?>
</div>
</li>
<li>
<lable>E-mail Address</lable>
<div>
<?php echo form_input($email);?>
</div>
</li>
<li>
<lable> Password</lable>
<div>
<?php echo form_password($password);?>
</div>
</li>
<li>
<lable> Retype Password</lable>
<div>
<?php echo form_password($password_conf);?>
</div>
</li>
<li>
<?php echo validation_errors();?>
</li>
<li>
<div>
<?php echo form_submit(array('name' => 'register'), 'Register');?>
</div>
</li>
</ul>
<?php echo form_close();?>
</body>
</html>
Controller
[/b]<?php
class User extends CI_Controller{
function __User() {
parent::__Controller();
$this->view_data['base_url'] = base_url();
$this->load->model('User_model');
}
function index() {
$this->register();
}
function register(){
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|xss_clean');
$this->form_validation->set_rules('name', 'Name', 'required|min_length[3]|max_length[20]|xss_clean');
$this->form_validation->set_rules('email', 'E-mail', 'required|min_length[3]|max_length[20]|xss_clean|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[3]|max_length[20]|xss_clean');
$this->form_validation->set_rules('password_conf', 'Re-type Password', 'required|min_length[3]|max_length[20]|xss_clean|matches[password]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('viewregister');
}
else {
$username = $this->input->post('username');
$name = $this->input->post ('name');
$email = $this->input->post ('email');
$password = $this->input->post ('password');
********Line 37*********** $this->Usermodel->register_user($username, $name, $email, $password);
}
}
}
Model
<?php
class Usermodel extends CI_Model {
function __construct() {
parent::__Model();
}
function register_user($username, $name, $email, $password) {
$shal_password = shal($password);
$query_str = "INSERT INTO tbregister (username, password, name, email) Value ('{$username}', '{$name}', '{$email}', '{password}')";
$this->db-query($query_sr, array($username,$name,$email,$shal_password));
}
}