Project Tutorials
Introduction Directory Structure Project Setup Remove index.php using htaccess Change Default Controller CSS Add in Project Create Login Page Design Validation on Login Login with Database Flashdata on Login Display Username after Login Logout Design Dashboard Page List user data form database Insert Data Flash message show if data inserted Delete data from datebase Edit data from datebase Active Inactive user status Show active users detail on home page Image Upload Edit Image View Image on Home PageFlash message show if data inserted
In this tutorial, we are going to create flash message show if data is inserted in database.
eg. If you create a login and user enters the wrong username and password so it will show the error message.
What is Flashdata
You can perform different session message depends what you you pass to view file from your controller.
Step 1 : Go you you dashboard controller and there we willl put the flash message code when our user data is inserted.
eg :
$this->session->set_flashdata('msg','User data has been inserted successfully!');
$this->session->set_flashdata('msg_class','alert-success');
Complete code of insert user detail.
public function add_user_detail(){
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('name','Full Name','required');
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('contact','Contact','required');
$this->form_validation->set_rules('status','Email','required');
if($this->form_validation->run())
{
$data = array(
'username' => $this->input->post('name'),
'email' => $this->input->post('email'),
'contact' => $this->input->post('contact'),
'status' => $this->input->post('status'),
);
$this->load->model('dashboard_model','userdata');
if($this->userdata->add_user($data))
{
//here i am creating a success flash message
$this->session->set_flashdata('msg','User data has been inserted successfully!');
$this->session->set_flashdata('msg_class','alert-success');
}
else{
$this->session->set_flashdata('msg','User data has not been inserted successfully!');
$this->session->set_flashdata('msg_class','alert-danger');
}
return redirect('dashboard');
}
else{
$this->load->view('add_user_detail');
}
}
Step 2 : Now, pass the flash msg on user list view page..
eg :
<?php
if($msg = $this->session->flashdata('msg'))
{
$msg_class = $this->session->flashdata('msg_class');
?>
<div class="alert <?php echo $msg_class; ?>">
<strong><?php echo $msg; ?></strong>
</div>
<?php
}
?>
Result :
Source Code:
Codeigniter tutorial for beginners
In this project. We are providing you, how to create small project in Codeign....
Source CodeElevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date