使用codeigniter 3将数据插入数据库时​​,页面变为空白

时间:2015-12-01 17:19:23

标签: php mysql codeigniter

我将数据插入数据库,当它插入页面时变为空白然后返回。

这是我的代码:

if ( ! $this->upload->do_upload('post_image'))
{
    $this->session->set_flashdata('post_message', $this->upload->display_errors());
    $this->session->set_flashdata('post_message_class', 'alert-danger');
    redirect('/user/profile/'.$identity, 'refresh');
}
else
{
    $uploaded = $this->upload->data();
    $post_text = "";                        
    // insert pos
    if(isset($uploaded['file_name']) && $uploaded['file_name'] == 0)
    {                       
        $post_text = '<img src="/uploads/images/'.$uploaded['file_name'].'" width="251px" alt="'.$uploaded['raw_name'].'" /><br>'.$this->input->post('post_text');                                  
    }
    else 
    {
        foreach ($uploaded as $images)
        {                                               
            $post_text .= '<img src="/uploads/images/'.$images['file_name'].'" width="251px" alt="'.$images['raw_name'].'" />';                                                 
        }
        $post_text .= $this->input->post('post_text');  
    }               

    $query = $this->user_model->insert_user_posts($this->input->post('poster_id'), $this->input->post('profile_id'), $this->input->post('post_type'), $post_text);
    $this->session->set_flashdata('post_message', 'Image has been posted!');
    $this->session->set_flashdata('post_message_class', 'alert-success');
    redirect('/user/profile/'.$identity, 'refresh');          
}

以下是模型的代码:

public function insert_user_posts($poster_id, $profile_id, $post_type, $post_text)
{
    // Users table.
    $data = array(
        'poster_id'     => $poster_id,
        'profile_id'    => $profile_id,
        'post_type'     => $post_type,
        'post_text'     => $post_text,
        'datetime'      => time()
    );

    $this->db->insert($this->tables['users_posts'], $data);

    if($this->db->affected_rows() > 0)
    {
        $this->set_message('upload_successful');
        return TRUE;
    }
    else
    {
        return FALSE;   
    }
}

另外,我使用的是:https://github.com/avenirer/MY_Upload

有没有办法在插入数据库时​​没有分页显示空白的情况下执行此操作?

0 个答案:

没有答案