Welcome Guest, Not a member yet? Register   Sign In
Message: Undefined variable: data
#1

[eluser]Adnan1984[/eluser]
Hello,i am using codeigniter version 2.1.2 and i have a little bit problem with variable.
here is my code:

In Controllers

Code:
class Site extends CI_Controller {

public function create_user(){
........................      
........................      
        
$data['success'] = 'successfully submitted!';
if($this->form_validation->run()== FALSE){
$this->load->view('test_view');
}else{
$this->load->model('get_model');
$this->get_model->user_insert();
$this->load->view('test_view',$data);
}
}

}

In Views

Code:
........................      
........................  
<?php echo $success; ?>
........................      
........................

I got error message and it says:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: success

Filename: views/test_view.php

Line Number: 85

Can you solve this problem?
Thanks
#2

[eluser]Sanjay Sarvaiya[/eluser]

you are forget to load var at.
Code:
if($this->form_validation->run()== FALSE){
   $data['success'] = '';
   $this->load->var($data)
   $this->load->view('test_view');
}
#3

[eluser]rochellecanale[/eluser]
You forgot to declare the data
Use this:
Code:
$data['success'] = 'successfully submitted!';
if($this->form_validation->run()== FALSE){
$this->load->view('test_view',$data);  // you forgot to declare the data variable
#4

[eluser]Adnan1984[/eluser]
Now i got this solution. Thanks




Theme © iAndrew 2016 - Forum software by © MyBB