CodeIgniter Forums
insert query stalling when trying to pass data stored in session - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: insert query stalling when trying to pass data stored in session (/showthread.php?tid=52280)



insert query stalling when trying to pass data stored in session - El Forum - 06-04-2012

[eluser]Brad K Morse[/eluser]
I store a piece of data in session, then when I make an insert into the database, I pass that in, like this.

Code:
$data = array(
'age' => $this->session->userdata('age'),
'weight' => $this->input->post('weight')
);

$this->db->insert('table', $data);

It will stall with me passing the age stored in the session.

If I remove that and just past in a number, like below, it works without a problem

Code:
$data = array(
'age' => 20,
'weight' => $this->input->post('weight')
);

$this->db->insert('table', $data);

I echo'd out $this->session->userdata('age') and it displays the appropriate age.

I also tried inserting the value into a hidden input and inserting it into the table w/o directly calling it from session and it still stalls.

Any help is appreciated.


insert query stalling when trying to pass data stored in session - El Forum - 06-04-2012

[eluser]Cristian Gilè[/eluser]
Try to cast the session value:

Code:
$data = array(
'age' => (int)$this->session->userdata('age'),
'weight' => $this->input->post('weight')
);

$this->db->insert('table', $data);



insert query stalling when trying to pass data stored in session - El Forum - 06-05-2012

[eluser]Brad K Morse[/eluser]
No luck.

I did

Code:
print_r($this->session->all_userdata());

I even stored the data into a variable, then tried passing it into the insert query.

Code:
$value = $this->session->all_userdata();

$value['age'];

I still get the same problem.

I've used session data in past applications when passing it into a db query, it can't be permission errors as the data is stored in session and prints out whenever I call it.


insert query stalling when trying to pass data stored in session - El Forum - 06-05-2012

[eluser]Cristian Gilè[/eluser]
Quote:
Code:
$value = $this->session->all_userdata();

$value['age'];

Are you able to echo the age value?


insert query stalling when trying to pass data stored in session - El Forum - 06-05-2012

[eluser]Brad K Morse[/eluser]
I think the problem was the database table column was expecting a number and not a string. I changed the column type to varchar2 for now until I change the output of the session variable to an integer.


insert query stalling when trying to pass data stored in session - El Forum - 06-05-2012

[eluser]Cristian Gilè[/eluser]
Did you try the cast solution?

Code:
$data = array(
'age' => (int)$this->session->userdata('age'),
'weight' => $this->input->post('weight')
);

$this->db->insert('table', $data);



insert query stalling when trying to pass data stored in session - El Forum - 06-05-2012

[eluser]Brad K Morse[/eluser]
Thanks Cristian, (int) did the trick.