$date['uid'] = $this->session->userdata('id');
//$date['uid'] = $this->input->post('uid');
$date['uname'] = $this->input->post('uname');
$data['title'] = $this->input->post('title');
$data['description'] = $this->input->post('desc');
$data['created'] = date('Y-m-d H:i:s');
I have been trying to save user id in news table where table name is uid. I have tried different methods to do so but in vain
$date['uid'] = $this->session->userdata('id');
when i try to get id using session it returns 0. and even when I try to post uid through form
<input type="hidden" value=<?php echo $this->session->userdata('id');?>
OR
<input type="hidden" value=<?php echo $_SESSION['id'];?>
it also saves 0 value to database
Did you try like this..
Load session library in application/config/autoload.php
.
$autoload['libraries'] = array('session');
Then
$data = array(
'uid' => $this->session->userdata('id');,
'uname' => $this->input->post('uname'),
'title' => $this->input->post('title'),
'description' => $this->input->post('desc'),
'created' => date('Y-m-d H:i:s')
);
//print_r($data);
$this->db->insert('table_name',$data); //inserts into table
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.