I am working on codeigniter. I did the sql query to insert the data into the database.my query is running perfectly and is shown in the database table.
But i want to display message if my data is inserted into the table(like data inserted successfully).
here is my controller code:
public function insert(){
$post=$this->input->post();
unset($post['submit']);
if($this->testimonial_model->insert_testimonial($post))
{
$this->session->set_flashdata('feedback',"Data inserted successfully.");
$this->session->set_flashdata('feedback_class','alert-success');
}else{
$this->session->set_flashdata('feedback',"failed to add, Please Try again");
$this->session->set_flashdata('feedback_class','alert-danger');
}
return redirect('testimonial_edit');
}
here is my model code:
public function insert_testimonial($insert){
return $this->db->insert('testimonial',$insert);
}
Here is my view code and my view file name is testimonial_edit
<?php
if($feedback=$this->session->flashdata('feedback')):
$feedback_class=$this->session->flashdata('feedback_class');
?>
<div class="row">
<div class="col-lg-6">
<div class="alert alert-dismissable <?php $feedback_class?>">
<?php $feedback?>
</div>
</div>
</div>
<?php
endif;
?>
Below this code my form code is there.
After filling form when i clicked on submit button the data is successfully inserted but it showing following error
404 Page Not Found
The page you requested was not found.
and url of this error page is
http://localhost/lalcoresidency/testimonials/dashbord
Please help me to find out the solution
You can't redirect to a view file, so try adding a method to the controller which simply loads the view; then redirect to that method:
public function insert(){
$post=$this->input->post();
unset($post['submit']);
if($this->testimonial_model->insert_testimonial($post))
{
$this->session->set_flashdata('feedback',"Data inserted successfully.");
$this->session->set_flashdata('feedback_class','alert-success');
}else{
$this->session->set_flashdata('feedback',"failed to add, Please Try again");
$this->session->set_flashdata('feedback_class','alert-danger');
}
redirect('current_controller_name/testimonial_edit');
}
/* add this function that you can redirect to,
and which will load the view file of the same name */
function testimonial_edit(){
$this->load->view('testimonial_edit');
}
As for your success message not displaying, try:
<?php if($this->session->flashdata('feedback')){ ?>
<div class="row">
<div class="col-lg-6">
<div class="alert alert-dismissable <?php echo $this->session->flashdata('feedback_class'); ?>">
<?php echo $this->session->flashdata('feedback'); ?>
</div>
</div>
</div>
<?php } ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With