插入会话ID和段

时间:2016-04-29 04:16:17

标签: php mysql codeigniter insert

我正在尝试获取段(3)并使用我的会话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']);
        }
    }

2 个答案:

答案 0 :(得分: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;
}

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

答案 1 :(得分:0)

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

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