Welcome Guest, Not a member yet? Register   Sign In
users update
#1

[eluser]penta997[/eluser]
Helo. I was wrote a function witch updating users data. But unfortunately, data don't save into a table, few colums has 0 value instead string. Please help.

this is models

Code:
function update_user()
       {      
           $this->db->where('USR_ID', $this->session->userdata('username'));
           $users = array(

               'USR_Nick' => $this->input->post('username'),
               'USR_Pass' => md5($this->input->post('pass')),
               'USR_LastModifyDate' => date('Y-m-d H:i:s')
           );

            $us = $this->db->update('users', $users);

            return $us;
          


       }

        function update_address()
        {
              $USR_ID = $this->db->query("select USR_ID from users where USR_Nick='".$this->session->userdata('username')."'")->row()->USR_ID;

              $this->db->where('USERS_USR_ID', $USR_ID);
              $address = array(
               'Country_COUNTRY_Id' => $this->input->post('country'),
               'State_STATE_ID' => $this->input->post('state'),
              
               'ADDR_CityName' => $this->input->post('miasto'),
               'ADDR_StreetName' => $this->input->post('ulica'),
               'ADDR_StreetNr' => $this->input->post('nr_ulicy'),
               'ADDR_HomeNr' => $this->input->post('nr_domu'),
               'ADDR_ZIP' => $this->input->post('zip'),
               'ADDR_Fax' => $this->input->post('fax')

           );
           $add = $this->db->update('address', $address);
          
           return $add;
          

          
        }


        function update_client()
        {


        

              $CLI_Name = $this->db->query("select c.CLI_Name from users u
            join address a on u.USR_ID = a.USERS_USR_ID
             join client c on a.ADDR_ID = c.Address_ADDR_ID where u.USR_Nick = '".$this->session->userdata('username')."'")->row()->CLI_Name;

              $this->db->where('CLI_Name', $CLI_Name);
             $client = array(
              
               'CLI_Email' => $this->input->post('email'),
               'CLI_Name' => $this->input->post('imie'),
               'CLI_LastName' => $this->input->post('nazwisko'),
               'CLI_NIP' => $this->input->post('nip'),
               'CLI_Regon' => $this->input->post('regon'),
               'CLI_Pesel' => $this->input->post('pesel'),
               'CLI_Phone' => $this->input->post('telefon')
           );

           $cli = $this->db->update('client',$client);
          

          

          

           return $cli;

       }

Controller function:
Code:
function edit_validation()
       {

             $widok['left'] = $this->get_category();
            $widok['right'] = $this->get_bestseller();



           $this->form_validation->set_rules('username', 'User Name', 'trim|required|min_length[4]');
           $this->form_validation->set_rules('pass', 'Password', 'trim|required|min_length[4]|max_length[32]');
           $this->form_validation->set_rules('pass2', 'Password Confirmation', 'trim|required|matches[pass]');
             $this->form_validation->set_rules('name', 'Name', 'trim|required|');
           $this->form_validation->set_rules('lastname', 'LastName', 'trim|required');
           $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
           $this->form_validation->set_rules('pesel', 'Pesel', 'trim|exact_length[11]|numeric');
           $this->form_validation->set_rules('regon', 'Regon', 'trim|exact_length[9]|numeric');
           $this->form_validation->set_rules('nip', 'Nip', 'trim|exact_length[10]|numeric');
           $this->form_validation->set_rules('telefon', 'Telefon', 'trim|exact_length[9]|numeric');
           $this->form_validation->set_rules('country', 'Country', 'trim|required');
          
           $this->form_validation->set_rules('miasto', 'Miasto', 'trim|required|max_length[20]');
           $this->form_validation->set_rules('ulica', 'Ulica', 'trim|required|max_lenght[15]');
           $this->form_validation->set_rules('nr_ulicy', 'Nr ulicy', 'trim|required|max_length[11]');
           $this->form_validation->set_rules('nr_domu', 'Nr domu', 'trim|required|max_length[4]');
           $this->form_validation->set_rules('zip', 'Zip', 'trim|required|max_length[11]');
           $this->form_validation->set_rules('fax', 'Fax', 'trim|max_length[10]|max_length[7]|numeric|alpha_dash');



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

           else
           {

                $this->load->model('Users_model');
                $query = $this->Users_model->update_user();
                $query2 = $this->Users_model->update_address();
                $query3 = $this->Users_model->update_client();

                if(($query) && ($query2) && ($query3))
                {

                    $data['data'] = 'Edycja konta zakonczona sukcesem';
                    $widok['tytul'] = 'Edycja konta powiodla sie';
                     $widok['center'] = $this->load->view('Ksiegarnia/update_success', $data, true);

                    $this->load->view('Ksiegarnia/index_logged', $widok);
                }

                else
                {
                    $data = 'Edycja nie powiodla sie';
                     $widok['center'] = $this->load->view('Ksiegarnia/update_success', $data, true);
                      $widok['tytul'] = 'błąd';

                    $this->load->view('Ksiegarnia/index_main', $widok);
                }
           }


       }




Theme © iAndrew 2016 - Forum software by © MyBB