ahmad
ahmad

Reputation: 3

if statement inside array : codeigniter

I have this function to edit all fields that come from the form and its works fine ..

function editRow($tableName,$id)
    {

    $fieldsData = $this->db->field_data($tableName);
    $data = array();
    foreach ($fieldsData as $key => $field)
    {
      $data[ $field->name ] = $this->input->post($field->name);
    }
    $this->db->where('id', $id);
    $this->db->update($tableName, $data);

  }

now I want to add a condition for Password field , if the field is empty keep the old password , I did some thing like that :

function editRow($tableName,$id)
{
    $fieldsData = $this->db->field_data($tableName);
    $data = array();
    foreach ($fieldsData as $key => $field)
    {
        if ($data[ $field->name ] == 'password' && $this->input->post('password') == '' )  
            {
              $data[ 'password' ] => $this->input->post('hide_password'),
              //'password'        => $this->input->post('hide_password'),
            }
            else {
               $data[ $field->name ] => $this->input->post($field->name)
            }
        }
        $this->db->where('id', $id);
        $this->db->update($tableName, $data);
    }

but I get error ( Parse error: syntax error, unexpected T_DOUBLE_ARROW in ... )

Html , some thing like this :

<input type="text"  name="password"  value="">
<input type="hidden"  name="hide_password"  value="$row->$password"  />

umm , any help ?

thanks ..

Upvotes: 0

Views: 3310

Answers (2)

hang2303
hang2303

Reputation: 11

if ($data[ $field->name ] == 'password' && $this->input->post('password') == '' )  
            {
              $data['password'] = $this->input->post('hide_password');
              //'password'        = $this->input->post('hide_password'),
            }
            else {
               $data[$field->name] = $this->input->post($field->name);
            }

Upvotes: 1

Zach
Zach

Reputation: 7940

I don't think "=>" is a valid PHP operator. Perhaps you meant to use "=", the assignment operator, on that line?

Upvotes: 2

Related Questions