Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将站点上载到Web服务器后无法将数据插入数据库_Php_Codeigniter - Fatal编程技术网

Php 将站点上载到Web服务器后无法将数据插入数据库

Php 将站点上载到Web服务器后无法将数据插入数据库,php,codeigniter,Php,Codeigniter,我一直在尽我最大的努力确保代码在我上传后能令人惊讶地完美工作。其他表单我都做得很好,除了这个表单,我想上传数据到数据库中,无论用户上传图像与否,数据都应该能够插入。。 我需要帮助 function add_student(){ $this->load->helper('url'); $this->load->library('form_validation'); $this->form_validation->set_error_d

我一直在尽我最大的努力确保代码在我上传后能令人惊讶地完美工作。其他表单我都做得很好,除了这个表单,我想上传数据到数据库中,无论用户上传图像与否,数据都应该能够插入。。 我需要帮助

 function add_student(){
    $this->load->helper('url');
    $this->load->library('form_validation');

    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');

    $this->form_validation->set_rules('fname', 'Student Firstname', 'required|min_length[2]|max_length[35]');

    $this->form_validation->set_rules('mname', 'Student Middlename', 'required|min_length[2]|max_length[35]');

    $this->form_validation->set_rules('lname', 'Student Lastname', 'required|min_length[2]|max_length[35]');

    $this->form_validation->set_rules('gender', 'Choose The Gender', 'required|min_length[2]|max_length[35]');

    $this->form_validation->set_rules('datepicker', 'Please pick a DOB', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('marital', 'Please Enter Marital Status', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('pob', 'Please Enter POB Residence', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('pobdistrict', 'Please Enter The POB District', 'required|min_length[2]|max_length[15]');

    $this->form_validation->set_rules('pobregion', 'Please Enter The POB Region', 'required|min_length[5]|max_length[15]');


    $this->form_validation->set_rules('residence', 'Please Enter The Residence', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('region', 'Please Enter The Region', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('district', 'Please Enter The District', 'required|min_length[5]|max_length[15]');


    $this->form_validation->set_rules('education', 'Please Enter The Education Level', 'required|min_length[5]|max_length[30]');

    $this->form_validation->set_rules('phone', 'Please Enter The Education Level', 'required|min_length[5]|max_length[15]');


        $fulpath ='../images/student_profile/';

        $config['upload_path'] = $fulpath;
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = "2048000"; // Can be set to particular file size , here it is 2 MB(2048 Kb)
        $config['x_axis'] = "768";
        $config['y_axis'] ="1024";

        $this->load->library('image_lib', $config);


        $this->image_lib->initialize($config);

        $this->image_lib->resize();

        $this->image_lib->crop();


       if($this->form_validation->run() == FALSE)

       {
           $this->load->model('fetch_data');

           $data['schoolname'] = $this->fetch_data->school_data();

           $data['partnername'] = $this->fetch_data->partner_data();

           $data['main_content'] = '/student/addstudent';

           $this->load->view('includes/template',$data);

       } else {

           $this->load->library('upload', $config);

           if(!$this->upload->do_upload()){

               echo '<h4 style="color: red;">

                    Failure! </h4>

                    <p style="color: red;">'.$this->upload->display_errors().'</p>';

               $data = array(

                   'student_fname' => $this->input->post('fname'),
                   'student_mname' => $this->input->post('mname'),
                   'student_lname' => $this->input->post('lname'),
                   'gender' => $this->input->post('gender'),
                   'dob' => $this->input->post('datepicker'),
                   'marital_status' => $this->input->post('marital'),
                   'education' => $this->input->post('education'),

                   'collage_id' =>$this->input->post('sname'),

                   'partner_id' =>$this->input->post('partner'),

                   'pob' => $this->input->post('pob'),
                   'region' => $this->input->post('pobregion'),
                   'district' => $this->input->post('pobdistrict'),

                   'residence' => $this->input->post('residence'),
                   'res_district' => $this->input->post('district'),

                   'res_region' => $this->input->post('region'),
                   'phone' => $this->input->post('phone'),

               );

               $this->load->model('insert_data');

               $this->insert_data->student_data($data);



           }

           else
           {
               $data_upload_files = $this->upload->data();

               $file_name =   $data_upload_files['file_name'];

               $image ='images/student_profile/'.$file_name;



               $data = array(
                   'student_fname' => $this->input->post('fname'),
                   'student_mname' => $this->input->post('mname'),
                   'student_lname' => $this->input->post('lname'),
                   'gender' => $this->input->post('gender'),
                   'dob' => $this->input->post('datepicker'),
                   'marital_status' => $this->input->post('marital'),
                   'education' => $this->input->post('education'),

                   'collage_id' =>$this->input->post('sname'),

                   'partner_id' =>$this->input->post('partner'),

                   'pob' => $this->input->post('pob'),
                   'region' => $this->input->post('pobregion'),
                   'district' => $this->input->post('pobdistrict'),

                   'residence' => $this->input->post('residence'),
                   'res_district' => $this->input->post('district'),

                   'res_region' => $this->input->post('region'),
                   'phone' => $this->input->post('phone'),

                   'student_profile_img' => $image ,
               );


               // Transfering Data To Model

               $this->load->model('insert_data');

               $this->insert_data->student_data($data);


           }

       }






    }
试试这个

在控制器中

function add_student()
{
    $this->load->helper('url');
    $this->load->model('insert_data');
    $this->load->library('form_validation');

    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
    $this->form_validation->set_rules('fname', 'Student Firstname', 'required|min_length[2]|max_length[35]');
    $this->form_validation->set_rules('mname', 'Student Middlename', 'required|min_length[2]|max_length[35]');
    $this->form_validation->set_rules('lname', 'Student Lastname', 'required|min_length[2]|max_length[35]');
    $this->form_validation->set_rules('gender', 'Choose The Gender', 'required|min_length[2]|max_length[35]');
    $this->form_validation->set_rules('datepicker', 'Please pick a DOB', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('marital', 'Please Enter Marital Status', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('pob', 'Please Enter POB Residence', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('pobdistrict', 'Please Enter The POB District', 'required|min_length[2]|max_length[15]');
    $this->form_validation->set_rules('pobregion', 'Please Enter The POB Region', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('residence', 'Please Enter The Residence', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('region', 'Please Enter The Region', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('district', 'Please Enter The District', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('education', 'Please Enter The Education Level', 'required|min_length[5]|max_length[30]');
    $this->form_validation->set_rules('phone', 'Please Enter The Education Level', 'required|min_length[5]|max_length[15]');


    $fulpath ='../images/student_profile/';

    $config['upload_path'] = $fulpath;
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size'] = "2048000"; // Can be set to particular file size , here it is 2 MB(2048 Kb)
    $config['x_axis'] = "768";
    $config['y_axis'] ="1024";

    $this->load->library('image_lib', $config);

    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    $this->image_lib->crop();

    if($this->form_validation->run() == FALSE){

        echo "Form validation false";
       /*$this->load->model('fetch_data');
       $data['schoolname'] = $this->fetch_data->school_data();
       $data['partnername'] = $this->fetch_data->partner_data();
       $data['main_content'] = '/student/addstudent';
       $this->load->view('includes/template',$data);*/

    } 
    else {

        $this->load->library('upload', $config);

        if(!$this->upload->do_upload())
        {
            echo '<h4 style="color: red;">
                Failure! </h4>
                <p style="color: red;">'.$this->upload->display_errors().'</p>';

            $data = array(
               'student_fname' => $this->input->post('fname'),
               'student_mname' => $this->input->post('mname'),
               'student_lname' => $this->input->post('lname'),
               'gender' => $this->input->post('gender'),
               'dob' => $this->input->post('datepicker'),
               'marital_status' => $this->input->post('marital'),
               'education' => $this->input->post('education'),
               'collage_id' =>$this->input->post('sname'),
               'partner_id' =>$this->input->post('partner'),
               'pob' => $this->input->post('pob'),
               'region' => $this->input->post('pobregion'),
               'district' => $this->input->post('pobdistrict'),
               'residence' => $this->input->post('residence'),
               'res_district' => $this->input->post('district'),
               'res_region' => $this->input->post('region'),
               'phone' => $this->input->post('phone'),
            );          

            $result = $this->insert_data->student_data($data);

            if ($result == TRUE) {
                echo "Success. (In top)";
            }
            else{
                echo "Faile. (In top)";
            }
        }
        else
        {
            $data_upload_files = $this->upload->data();
            $file_name =   $data_upload_files['file_name'];
            $image ='images/student_profile/'.$file_name;

            $data = array(
               'student_fname' => $this->input->post('fname'),
               'student_mname' => $this->input->post('mname'),
               'student_lname' => $this->input->post('lname'),
               'gender' => $this->input->post('gender'),
               'dob' => $this->input->post('datepicker'),
               'marital_status' => $this->input->post('marital'),
               'education' => $this->input->post('education'),
               'collage_id' =>$this->input->post('sname'),
               'partner_id' =>$this->input->post('partner'),
               'pob' => $this->input->post('pob'),
               'region' => $this->input->post('pobregion'),
               'district' => $this->input->post('pobdistrict'),
               'residence' => $this->input->post('residence'),
               'res_district' => $this->input->post('district'),
               'res_region' => $this->input->post('region'),
               'phone' => $this->input->post('phone'),
               'student_profile_img' => $image ,
            );

            $result = $this->insert_data->student_data($data);

            if ($result == TRUE) {
                echo "Success. (In bottom)";
            }
            else{
                echo "Faile. (In bottom)";
            }
        }
    }
}
试试这个

在控制器中

function add_student()
{
    $this->load->helper('url');
    $this->load->model('insert_data');
    $this->load->library('form_validation');

    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
    $this->form_validation->set_rules('fname', 'Student Firstname', 'required|min_length[2]|max_length[35]');
    $this->form_validation->set_rules('mname', 'Student Middlename', 'required|min_length[2]|max_length[35]');
    $this->form_validation->set_rules('lname', 'Student Lastname', 'required|min_length[2]|max_length[35]');
    $this->form_validation->set_rules('gender', 'Choose The Gender', 'required|min_length[2]|max_length[35]');
    $this->form_validation->set_rules('datepicker', 'Please pick a DOB', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('marital', 'Please Enter Marital Status', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('pob', 'Please Enter POB Residence', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('pobdistrict', 'Please Enter The POB District', 'required|min_length[2]|max_length[15]');
    $this->form_validation->set_rules('pobregion', 'Please Enter The POB Region', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('residence', 'Please Enter The Residence', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('region', 'Please Enter The Region', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('district', 'Please Enter The District', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('education', 'Please Enter The Education Level', 'required|min_length[5]|max_length[30]');
    $this->form_validation->set_rules('phone', 'Please Enter The Education Level', 'required|min_length[5]|max_length[15]');


    $fulpath ='../images/student_profile/';

    $config['upload_path'] = $fulpath;
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size'] = "2048000"; // Can be set to particular file size , here it is 2 MB(2048 Kb)
    $config['x_axis'] = "768";
    $config['y_axis'] ="1024";

    $this->load->library('image_lib', $config);

    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    $this->image_lib->crop();

    if($this->form_validation->run() == FALSE){

        echo "Form validation false";
       /*$this->load->model('fetch_data');
       $data['schoolname'] = $this->fetch_data->school_data();
       $data['partnername'] = $this->fetch_data->partner_data();
       $data['main_content'] = '/student/addstudent';
       $this->load->view('includes/template',$data);*/

    } 
    else {

        $this->load->library('upload', $config);

        if(!$this->upload->do_upload())
        {
            echo '<h4 style="color: red;">
                Failure! </h4>
                <p style="color: red;">'.$this->upload->display_errors().'</p>';

            $data = array(
               'student_fname' => $this->input->post('fname'),
               'student_mname' => $this->input->post('mname'),
               'student_lname' => $this->input->post('lname'),
               'gender' => $this->input->post('gender'),
               'dob' => $this->input->post('datepicker'),
               'marital_status' => $this->input->post('marital'),
               'education' => $this->input->post('education'),
               'collage_id' =>$this->input->post('sname'),
               'partner_id' =>$this->input->post('partner'),
               'pob' => $this->input->post('pob'),
               'region' => $this->input->post('pobregion'),
               'district' => $this->input->post('pobdistrict'),
               'residence' => $this->input->post('residence'),
               'res_district' => $this->input->post('district'),
               'res_region' => $this->input->post('region'),
               'phone' => $this->input->post('phone'),
            );          

            $result = $this->insert_data->student_data($data);

            if ($result == TRUE) {
                echo "Success. (In top)";
            }
            else{
                echo "Faile. (In top)";
            }
        }
        else
        {
            $data_upload_files = $this->upload->data();
            $file_name =   $data_upload_files['file_name'];
            $image ='images/student_profile/'.$file_name;

            $data = array(
               'student_fname' => $this->input->post('fname'),
               'student_mname' => $this->input->post('mname'),
               'student_lname' => $this->input->post('lname'),
               'gender' => $this->input->post('gender'),
               'dob' => $this->input->post('datepicker'),
               'marital_status' => $this->input->post('marital'),
               'education' => $this->input->post('education'),
               'collage_id' =>$this->input->post('sname'),
               'partner_id' =>$this->input->post('partner'),
               'pob' => $this->input->post('pob'),
               'region' => $this->input->post('pobregion'),
               'district' => $this->input->post('pobdistrict'),
               'residence' => $this->input->post('residence'),
               'res_district' => $this->input->post('district'),
               'res_region' => $this->input->post('region'),
               'phone' => $this->input->post('phone'),
               'student_profile_img' => $image ,
            );

            $result = $this->insert_data->student_data($data);

            if ($result == TRUE) {
                echo "Success. (In bottom)";
            }
            else{
                echo "Faile. (In bottom)";
            }
        }
    }
}


不能在模型中加载视图。使用控制器执行此操作OK,但无论哪种方式,数据都应在加载之前插入,但不将数据数组移动到模型中我将如何处理模型内的if条件??我认为这不是问题所在,因为数据正在传递到模型中。我没有看到任何答案。您不能在模型中加载视图。使用控制器执行此操作OK,但无论哪种方式,数据都应在加载之前插入,但不将数据数组移动到模型中我将如何处理模型内的if条件??我不认为这是问题所在,因为数据正在传递给模型。我还没有看到任何答案。你能帮忙吗?因为我按要求插入了所有数据。。。。。我已经调查了表单验证找不到错误删除表单验证并尝试回答你问题的答案在表单中validation@user3551487很高兴提供帮助:)欢迎您,尽管我需要以下代码的另一个帮助,该代码从数据库中获取url问题是它显示了一个损坏的图像
$path=基本url().str\u替换(“./”,“,$row->student\u profile\u img);回声“您能帮忙吗,因为我按要求插入了所有数据。。。。。我已经调查了表单验证找不到错误删除表单验证并尝试回答你问题的答案在表单中validation@user3551487很高兴提供帮助:)欢迎您,尽管我需要以下代码的另一个帮助,该代码从数据库中获取url问题是它显示了一个损坏的图像
$path=基本url().str\u替换(“./”,“,$row->student\u profile\u img);回声“
public function student_data($data){

    if ($this->db->insert('student_profile', $data)) {

        return TRUE;
    }
    else{

        return FALSE;
    }

}