0

This is opinion based question.
I am working in Codeigniter framework I have multi-step user registration form What i am doing is collecting all data in session array validating it and inserting in database.Till now all things are working fine but now i have added image upload form along with form i.e user will upload images while registration.Now i have doubt here i have two different Controllers for user registration[where i collect all form fields data in session array] and other controller for image upload. now what currently i am doing is saving user data in database and running update query to update user row for inserting images i.e when user register a unique id is assigned to it then by that unique id i am updating user data for inserting images[sounds ridiculous] but i want along with form data images name are also added to database at once now need of update query?? I hope my question is clear??All things are functional but i want it in prpoer way

//My view 
//image upload form
         <?php echo form_open_multipart('upload/do_upload', array('class' => 'upload-image-form'));?>
            <div class="form-inline">
              <div class="form-group">
                <input type="file" name="uploadfile[]" accept = "image/*" multiple = "multiple" size="20" /> <br />
              </div>
              <button type="submit" value="upload" class="btn btn-sm btn-primary" name="submit">Upload files</button>
            </div>


// user registration form 
     <form action="<?php echo base_url('Camping_register/register') ?>" method="post">
                        <h2>Camping <span class="red"><strong>Rent Details</strong></span></h2>
                        <label for="business_name">Business Name</label>
                        <input type="text" id="business_name" name="business_name" placeholder="enter your business name">
                        <label for="rental_description">Rental Description</label>
                        <textarea type="text" id="rental_description" name="rental_description"></textarea>
                        <button type="submit">REGISTER</button>
                        <?php
                        $message = $this->session->flashdata('msg');
                        if($message){
                        echo '<div id="error_text">' . '<strong>'.$message .'</strong>'. '</div>';
                        }   
                        ?>

                    </form>





//user registration form controller 
$new_form=array();
            $new_form['business_name']=$this->input->post("business_name");
            $new_form['rental_description']=$this->input->post("rental_description");
            // phase 2 data appended to session
            $this->session->set_userdata($new_form);


        /* as we can see i added user input into session array 

         **/

//image upload controller

  $this->upload->initialize(array(
                "upload_path"       =>  $path,
                "allowed_types"     =>  "gif|jpg|png",
                "max_size"          =>  '2048',
                "encrypt_name"      => TRUE,
            ));


            if($this->upload->do_multi_upload("uploadfile")){

                //case success
                $data['upload_data'] = $this->upload->get_multi_upload_data();
                $this->session->set_userdata($data);
                var_dump($data);
                var_dump($this->session->all_userdata());

                //let's call model function for inserting images into database

                 //$img['images'] = $this->Camping_model->insert_images($data);
                 //var_dump($img);
                echo '<strong>'.'<p class = "bg-success">' . count($data['upload_data']) . 'File(s) successfully uploaded.</p>.'.'</strong>';


            } else {   
                // Output the errors
                $errors = array('error' => $this->upload->display_errors('<p class = "bg-danger">', '</p>'));              
                foreach($errors as $k => $error){
                    echo $error;
                }

            }

I need to know proper way of doing this so require suggestions how these things are applied in MVC
Plz help me also in this

// this is how model looks like 
   $session_data = $this->session->userdata('sessiondata');
        $user_id = $session_data['user_id'];

        $filePath = $upload_data['file_name'];
        //print_r(LARGEPATH);
        $query = "UPDATE `tbl_usrs` set profile_picture='".$filePath."' where user_id='".$user_id."'";
       // $this->db->query($query,array($img));


    /* as we can see i am running update query this only
     * possible only when i have unique user_id but at the
      at time of registration no unique user_id is available as 
      he is not yet registrated **/

So what i want user data +images are inserted all at once in table ?? how can i achieve this ??
i will be very thankfull for any help

2
Contributors
1
Reply
24
Views
1 Year
Discussion Span
Last Post by diafol
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.