Undefined variable Codeigniter-Collection of common programming errors
I have this error on my view and i can’t find where is the problem
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: errors
Filename: views/register_user.php
Line Number: 5
view:
and here controller
function register(){
if($_POST){
$config=array(
array(
'field'=>'username',
'label'=>'Username',
'rules'=>'trim|required|min_length[3]|is_unique[users.username]'
),
array(
'field'=>'password',
'label'=>'Password',
'rules'=>'trim|required|min_length[5]|max_length[15]'
),
array(
'field'=>'password2',
'label'=>'Password Confirmed',
'rules'=>'trim|required|min_length[5]|matches[password]'
),
array(
'field'=>'user_type',
'label'=>'User Type',
'rules'=>'required'
),
array(
'field'=>'email',
'label'=>'Email',
'rules'=>'trim|required|is_unique[users.email]|valid_email'
)
);
$this->load->library('form_validation');
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){
$data['errors']=validation_errors();
} else {
$data=array(
'username'=>$_POST['username'],
'password'=>$_POST['password'],
'user_type'=>$_POST['user_type']
);
$this->load->model('user');
$userid=$this->user->create_user($data);
$this->session->set_userdata('userID',$userid);
$this->session->set_userdata('user_type',$_POST['user_type']);
redirect(base_url().'posts');
}
}
$this->load->helper('form');
$this->load->view('header');
$this->load->view('register_user');
$this->load->view('footer');
}
i’m starting using Codeigniter and i can’t find the problem…
-
Change this:
UPDATE: But you have a lot of other problems in your code. You need to clear it. For example: You didn’t load the errors. And you let to create user without validation.
-
Please try this
Originally posted 2013-11-09 22:46:58.