1

I tried store data in a session using CI in my register function.

public function register(){
    $firstname = $this->input->post('firstname');    
    $email= $this->input->post('email');
    $dev_info = array('fname'=>$firstname, 'eaddress'=>$email);
    $this->session->set_userdata($dev_info);
}

and in my other function verification I want to get the session data and pass to the view

public function verification(){
    $data['fname'] = $this->session->userdata('fname');
    $data['eaddress'] = $this->session->userdata('eaddress');
    $this->load->view('index', $data);
}

and I want to save its value in input type

in the view

<input type="hidden" id="firstname" value="<?php echo $fname?>">
<input type="hidden" id="email" value="<?php echo $eaddress?>">

but i am having a hard time saving its value in an input everytime I check using view source. Please help!

1
  • Have you loaded your session library? Commented Mar 9, 2016 at 8:46

2 Answers 2

2

you can get session variables one by one also

$first_name    = $this->session->userdata('fname');
$email_address = $this->session->userdata('eaddress');

in view you can use these variables or you can write code for view like this

<input type="hidden" id="firstname" value="<?php echo $this->session->userdata('eaddress'); ?>">
<input type="hidden" id="email" value="<?php echo $this->session->userdata('fname')?>">
Sign up to request clarification or add additional context in comments.

6 Comments

i tried it sir but still failed. i don't know what is wrong.
what type of error you get? is you load session library?
nothing. I just dont see the value in my input when I echo it. yes. Actually i successfully save data in a session. when I console.log the the session value in an ajax call.
print_r($fname) for check you session
you have set same id for both hidden input fields. id must be unique so first change id's
|
0

in controller create session for ur input data

$data['fname'] = $this->session->userdata('fname');
$data['eaddress'] = $this->session->userdata('eaddress');

in view retrieve the input data from the session by adding the value by set_value

<input type="hidden" id="firstname" value="<?php echo set_value('fname'); ?>">
<input type="hidden" id="email" value="<?php echo set_value('eaddress'); ?>">

3 Comments

add some description to it
what description? i m newbie here
A description of the code, that why it will solve and issue and how

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.