How To Display success message using php codeigniter

how to display a success message when user registration is successful. So you will use the flash message in your web application to show the success message.

Hello, Guys. In this tutorial, I will help you how to display success messages after successful form submission. It will display o the visitors when a visitor registration on your website. If you are developing your websites using the PHP Codeigniter framework you need to use the flash message in your web application to show the success message or error message. Using flash messages in your web application you can display a success or error alert within or a pop-up option.

I will give you an example and source code below of this content. I think these codes help you to display a user-friendly message in your web application.

First, you need to know how a flash message is working on your web page?

In Codeigniter, a flash message stores some data in a session variable that you want to store in a session variable. The session variable defines after your work is done and you can put the reliable information in the session variable and put a redirect page after register success.


Then go to the redirect page, where you show the message. On the redirect page, you will call the session variable. If your registration is a success then it shos the success message or shows the error message to registration failed.


To store a message in a session variable using the code:

$this->session->set_flashdata(‘category_success’, ‘Registration Successful’);

When you using set_flashdata for showing the message. So you have to need a session library in your Codeigniter project, which you will be set in the parent constructor.


Library helper source code:

public function __construct(){




    // Session



The library function is used in the parent constructor of the CodeIgniter controller page or model page. Then you store a message vlue in a session variable. That’s like



public function registration($data){

$sql_query=$this->db->insert(‘Table Name’,$data);


$this->session->set_flashdata(‘success’, ‘Account Create Succcess’);



$this->session->set_flashdata(‘error’, ‘Somthing worng. Error!!’);




Redirect Page:

if ($this->session->flashdata(‘success’)) {


php echo $this->session->flashdata(‘success’);


php }

if ($this->session->flashdata(‘error’)) {


echo $this->session->flashdata(‘error’);



We have more Codeigniter helpful tutorials you can see that: Codeigniter -Tutorial

Thanks for visiting our website. To get the latest and more helpful tutorial, follow our website because DataInFlow is a platform, where you can get the text tutorial and video tutorial of a different kind of programming language like PHP, HTML, Javascript, Jquery, CSS3 and get some technology and latest news. Thanks!


  1. Example

How to show success messages using Codeigniter?

I have a form layout, when I press submit button the data from this page save into the database. I can print my form validation errors on the same page but I cannot print my success message on this page, I can print the success message into another page, how can I show the message on the same page plz help.

Here is the controller:

function addRoom(){

$data[‘title’] = ‘Add Room’;

$data[‘main_content’] = ‘config/addRoom’;

$data[‘roomlists’] = $this->config_mdl->get_room_info();

$this->load->view(‘_base/layout’, $data);


function roomAdd(){

$this->form_validation->set_rules(‘roomType’, ‘Room Type’, ‘trim|required|xss_clean’);

$this->form_validation->set_rules(‘roomName’, ‘Room Name’, ‘trim|required|xss_clean’);

$this->form_validation->set_rules(‘roomDetails’, ‘Room Details’, ‘trim|required|xss_clean’);

$this->form_validation->set_error_delimiters(‘<div class=”alert alert-danger” role=”alert”>’, ‘</div>’);

if ($this->form_validation->run() == FALSE) {


} else {

$roomdata = array(‘room_type’ => $this->input->post(‘roomType’),

‘room_name’ => $this->input->post(‘roomName’),

‘room_details’ => $this->input->post(‘roomDetails’));




 Here is my model:

function roomAdd($roomdata)    {

return $this->db->insert(‘tbl_room_info’, $roomdata);



Here is My view:

    <div class=”panel-body”>

    echo validation_errors();

$attributes = array(‘class’ => ‘form-horizontal’, ‘role’ => ‘form’);

                        echo form_open_multipart(‘config/roomAdd’, $attributes);

    <div class=”form-group”>

        <label for=”roomTypes” class=”col-md-2 control-labels”>Rooms Types</label>

        <div class=”col-md-2″>

        <select name=”roomType” class=”form-control”>


        <option value=”1″>1</option>

        <option value=”3″>3</option>




    <div class=”form-group”>

        <label for=”roomName” class=”col-md-2 control-label”>Rooms Names</label>

        <div class=”col-md-6″>

        <input type=”text” class=”form-control” name=”roomName” placeholder=”Type Room Name” />



    <div class=”form-group”>

        <label for=”roomDetails” class=”col-sm-2 control-label”>Room Details</label>

        <div class=”col-sm-6″>

        <textarea class=”form-control” name=”roomDetails” rows=”3″></textarea>



    <div class=”form-group”>

        <div class=”col-sm-offset-2 col-sm-6″>

        <button type=”submit” class=”btn btn-primary”>Submit</button>



echo form_close(); 



  • E_ERROR :
  • fatal runtime error execution of script has been halted
  • nonfatal runtime error execution of script has been halted
  • E_PARSE :
  • compile-time error is generated by the parser
  • E_NOTICE :
  • The script found something that might be an error
  • Fatal errors that occurred during the initial startup of the script
  • Nonfatal errors that occurred during the initial startup of the script
  • E_ALL :


People also ask

How do I display PHP errors,

How do I turn off display errors in PHP,

How do I enable display errors in PHP INI,

Which function is used to display the errors.

Add a Comment

Your email address will not be published.