Fatal error: Call to undefined function validation_errors() using codeIgniter here's my comments.php view
<?php echo validation_errors(); ?>
<?php echo form_open('news/comments'); ?>
Name <input type="text" name="comment_name"></input><br />
Email <input type="text" name="comment_email"></input><br />
Comment<input type="text" name="comment_body"></input><br />
<input type="submit" name="submit" value="Comment it" ></input>
</form>
here's my news_model.php
<?php
class News_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
//set comment
public function set_comment()
{
$this->load->helper('url');
$this->load->helper('date');
$data_c = array(
'comment_name' => $this->input->post('comment_name'),
'comment_email' => $this->input->post('comment_email'),
'comment_body' => $this->input->post('comment_body'),
);
return $this->db->insert('comments', $data_c);
}
}
here my controller news.php
<?php
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
}
public function create_comment()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('comment_name', 'comment_name', 'required');
$this->form_validation->set_rules('comment_email', 'comment_email', 'required');
$this->form_validation->set_rules('comment_body', 'comment_body', 'required');
if ($this->form_validation->run() === FALSE)
{
echo 'failed'; //just for debugging
}
else
{
$this->news_model->set_comment();
$this->load->view('news/success');
}
}
}
in routes.php
$route['news/comments'] = 'news/comments';
how to resolve ?cannot insert data into database because of fatal error.
I don't see you loading your validation_form library anywhere - are you sure it is loaded?
Either in autoload, or else:
$this->load->library('form_validation');