2016-04-29 26 views
0

我试图让段(3),它与我的会话ID,但即时通讯卡插入到我的新表..任何想法插图会话ID和段

型号

function old_report_create() 
     { 
$reportID = $this->input->post('ReportID'); 
      $userID_staff = $this->session->userdata('StaffID'); 
      if (isset($reportID) && isset($userID)) { 
       $new_read = array(
        'ReportID' => $reportID, 
        'StaffID' => $userID_staff, 
       ); 
       return $this->db->insert('Read_Report', $new_read); 
      } 
      return FALSE; 
     } 

查看

<?= form_open('main/add_old_report'); ?> 
     <?= form_hidden('ReportID', $this->uri->segment(3)); ?> 
     <p><input type="submit" value="Read Report"/></p> 
     </form> 

控制器

function add_old_report() 
    { 
     if ($query = $this->report_model->old_report_create()) { 

      $this->session->set_flashdata('messagetwo', 'You marked report as read'); 
      redirect('main/comments/' . $_POST['ReportID']); 

     } else { 
      $this->session->set_flashdata('messagetwo', 'Sorry not this time'); 
      redirect('main/comments/' . $_POST['ReportID']); 
     } 
    } 
+0

什么是问题和加载视图时请求的网址是什么? –

+0

问题是它没有插入数据,你怎么表示请求url。即时尝试请求应该是一个数字的url的第三部分,然后我想要插入该号码 – Beep

+0

我的意思是,当你的观点被加载,那么浏览器地址中的http url是什么? –

回答

0

你有这个更新你的模型功能:

型号功能:

function old_report_create() 
{ 
    $reportID = $this->input->post('ReportID'); 
    $userID = $this->session->userdata('StaffID'); 
    if (isset($reportID) && isset($userID)) { 
     $new_read = array(
      'ReportID' => $reportID, 
      'StaffID' => $userID, 
     ); 
     $this->db->insert('Read_Report', $new_read); 
     return $this->db->insert_id(); 
    } 
    return FALSE; 
} 

希望这将有助于解决您的问题!

+0

@Beep,用这个更新你的模型函数 –

+0

5分钟前我刚刚完成了自己的工作,但这是正确的(比我的整洁一点)谢谢。 – Beep

0

也许字段类型是错误的。因为,codeigniter会在值附近添加引号。所以Mysql读取它们为String,而不是预期的类型?

$new_read = array(
     'ReportID' => (int)$reportID, 
     'StaffID' => $userID_staff 
    );