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

用户名

我一直在尽力确保代码在上载其他表格后能出乎意料地正常工作,除了我希望将数据上载到数据库(无论用户上载图像还是不上载数据)之外,其他形式我都做得很好应该可以插入..我需要帮助。

 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);


           }

       }






    }

我将数据从控制器传递到的模型如下:

public function student_data($data){

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

    if($this->db->affected_rows() > 0)
    {
        // Code here after successful insert

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

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

        return true; // to the controller

    }else{

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

        $this->load->view('adminhome',$data);

    }
}
阿卜杜拉·尼拉姆(Abdulla Nilam)

试试这个

在控制器中

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)";
            }
        }
    }
}

在模型中

public function student_data($data){

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

        return TRUE;
    }
    else{

        return FALSE;
    }

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将文件上传到Web服务而不保存到服务器,数据库或本地

来自分类Dev

将文件上传到Web服务而不保存到服务器,数据库或本地

来自分类Dev

如何将sqlite3数据库上传到Web服务器?

来自分类Dev

将图像上传到服务器并存储在MySQL数据库中

来自分类Dev

将多个文件上传到服务器并将路径复制到数据库

来自分类Dev

使用Android和PHP将图像上传到服务器(MySQL数据库)

来自分类Dev

将照片上传到数据库(到服务器而不是本地主机)

来自分类Dev

将多个图像上传到Apache服务器上的mysql数据库

来自分类Dev

将图像上传到服务器并将图像路径存储在mysql数据库中

来自分类Dev

将大型数据库文件上传到服务器

来自分类Dev

如何从Android程序将SQLite数据库文件上传到FTP服务器

来自分类Dev

将大型数据库文件上传到实时服务器

来自分类Dev

将图像上传到 MySQL 数据库时出现问题,它不会输入但将图像上传到服务器

来自分类Dev

如何使用php和android将多个图像上传到服务器(mysql数据库)

来自分类Dev

我如何使用react native expo image将图像上传到本地服务器PHP /数据库MySQL

来自分类Dev

如何将文件上传到数据库,而不仅仅是使用php的服务器

来自分类Dev

无法将数据库导入服务器

来自分类Dev

无法将图片上传到真实的Web服务器

来自分类Dev

反复将数据上传到服务器

来自分类Dev

将图像上传到服务器的最佳方法是什么?保存在数据库还是服务器文件夹中?

来自分类Dev

无法将图像上传到数据库

来自分类Dev

将数据上传到服务器后出现404错误

来自分类Dev

如何通过arduino gprs模块将数据上传到Web服务器

来自分类Dev

ConnectionTimeoutException:将数据插入mongodb数据库时找不到合适的服务器

来自分类Dev

PHP / MySQL-将JSON数据插入Bluehost服务器上的数据库,空的数据库条目

来自分类Dev

DreamFactory:如何将图像上传到文件服务器并将图像的路径保存在数据库中?

来自分类Dev

将默认数据库更改为MySQL后,WSO2 APIM服务器无法启动

来自分类Dev

将数据插入数据库后,无法在 Laravel 中显示数据库中的数据

来自分类Dev

提高将数据上传到数据库的性能

Related 相关文章

  1. 1

    将文件上传到Web服务而不保存到服务器,数据库或本地

  2. 2

    将文件上传到Web服务而不保存到服务器,数据库或本地

  3. 3

    如何将sqlite3数据库上传到Web服务器?

  4. 4

    将图像上传到服务器并存储在MySQL数据库中

  5. 5

    将多个文件上传到服务器并将路径复制到数据库

  6. 6

    使用Android和PHP将图像上传到服务器(MySQL数据库)

  7. 7

    将照片上传到数据库(到服务器而不是本地主机)

  8. 8

    将多个图像上传到Apache服务器上的mysql数据库

  9. 9

    将图像上传到服务器并将图像路径存储在mysql数据库中

  10. 10

    将大型数据库文件上传到服务器

  11. 11

    如何从Android程序将SQLite数据库文件上传到FTP服务器

  12. 12

    将大型数据库文件上传到实时服务器

  13. 13

    将图像上传到 MySQL 数据库时出现问题,它不会输入但将图像上传到服务器

  14. 14

    如何使用php和android将多个图像上传到服务器(mysql数据库)

  15. 15

    我如何使用react native expo image将图像上传到本地服务器PHP /数据库MySQL

  16. 16

    如何将文件上传到数据库,而不仅仅是使用php的服务器

  17. 17

    无法将数据库导入服务器

  18. 18

    无法将图片上传到真实的Web服务器

  19. 19

    反复将数据上传到服务器

  20. 20

    将图像上传到服务器的最佳方法是什么?保存在数据库还是服务器文件夹中?

  21. 21

    无法将图像上传到数据库

  22. 22

    将数据上传到服务器后出现404错误

  23. 23

    如何通过arduino gprs模块将数据上传到Web服务器

  24. 24

    ConnectionTimeoutException:将数据插入mongodb数据库时找不到合适的服务器

  25. 25

    PHP / MySQL-将JSON数据插入Bluehost服务器上的数据库,空的数据库条目

  26. 26

    DreamFactory:如何将图像上传到文件服务器并将图像的路径保存在数据库中?

  27. 27

    将默认数据库更改为MySQL后,WSO2 APIM服务器无法启动

  28. 28

    将数据插入数据库后,无法在 Laravel 中显示数据库中的数据

  29. 29

    提高将数据上传到数据库的性能

热门标签

归档