Welcome Guest, Not a member yet? Register   Sign In
sql only fires if there is a change in update form
#1

[eluser]joehopkins[/eluser]
Hi,

I'm having an issue with an update form. It's a 'client details' form where the fields are pre-populated with the data from the DB.

Basically, the form only updates if you modify a text field, i.e. the text field submitted is a different value from before. If you don't do this, e.g. not change anything or merely select a checkbox the form sends the variables to the model but the model doesn't seem to execute the sql.

After testing, I know the form is sending the data, and I know the model is receiving it. It's just that it doesn't seem to execute the query at all. affected_rows() is zero and it returns no errors.

It's as if CI checks cross checks the fields before executing the SQL.

But if you modify a text field it all works swimmingly-well.

My code is massive so I'll post a summary:

Controller:

Code:
if ($this->form_validation->run() == FALSE)
    {
     //load views etc
    }
    else
    {
      $title = $this->input->post('title');
      $forename = $this->input->post('forename');
      //etc...
      $this->load->model('Clients_model');

      $update_sql = $this->Clients_model->update_client(
                               $title,
                               $forename,
                               $surname,
                               $dob,
                               $email,
                               $address1,
                               $address2,
                               $town,
                               $county_state_id,
                               $address_code,
                               $country_id,
                               $alt_address1,
                               $alt_address2,
                               $alt_town,
                               $alt_county_state_id,
                               $alt_address_code,
                               $alt_country_id,
                               $use_alt_address,
                               $phone_land,
                               $phone_mobile,
                               $client_type,
                               $cancer_profile,
                               $communication_method,
                               $involvement,
                               $status,
                               $client_id
      );
      $this->session->set_flashdata('msg', $update_sql);
      redirect('/clients', 'refresh');
    }
Model
Code:
function update_client($title,
                         $forename,
                         $surname,
                         $dob,
                         $email,
                         $address1,
                         $address2,
                         $town,
                         $county_state_id,
                         $address_code,
                         $country_id,
                         $alt_address1,
                         $alt_address2,
                         $alt_town,
                         $alt_county_state_id,
                         $alt_address_code,
                         $alt_country_id,
                         $use_alt_address,
                         $phone_land,
                         $phone_mobile,
                         $client_type,
                         $cancer_profile,
                         $communication_method,
                         $involvement,
                         $status,
                         $client_id
    )
{
             $this->sql = 'UPDATE client
                           SET
                           title = ?,
                           forename = ?,
                           surname = ?,
                           dob = ?,
                           email = ?,
                           address1 = ?,
                           address2 = ?,
                           town = ?,
                           county_state_id = ?,
                           address_code = ?,
                           country_id = ?,
                           alt_address1 = ?,
                           alt_address2 = ?,
                           alt_town = ?,
                           alt_county_state_id = ?,
                           alt_address_code = ?,
                           alt_country_id = ?,
                           use_alt_address = ?,
                           phone_land = ?,
                           phone_mobile = ?,
                           status = ?
                           WHERE
                           client_id = ?
                           ';
             $this->query = $this->db->query($this->sql, array(
                       $title,
                       $forename,
                       $surname,
                       $dob,
                       $email,
                       $address1,
                       $address2,
                       $town,
                       $county_state_id,
                       $address_code,
                       $country_id,
                       $alt_address1,
                       $alt_address2,
                       $alt_town,
                       $alt_county_state_id,
                       $alt_address_code,
                       $alt_country_id,
                       $use_alt_address,
                       $phone_land,
                       $phone_mobile,
                       $status,
                       $client_id
                       ));
             if ( $this->db->affected_rows() == 1)
             {
              //etc
             }
}




Theme © iAndrew 2016 - Forum software by © MyBB