0
votes

I have extended the menu_custom table in drupal to add role1, role2 and role3 fields and now when I try to update the values using the following query. The fields are not getting updated and the drupal shows no error in executing the query. I think there is a problem with the condition but I could not figure out where the problem is. Kindly help me to resolve this problem.

db_update('menu_custom')
->fields(array('role1','role2','role3'))
->values(array(
              'role1' => $form_state['values']['role1'],
              'role2' => $form_state['values']['role2'],
              'role3' => $form_state['values']['role3'],

))
->condition('title',$form_state['values']['title'])
->execute();
    }
1

1 Answers

0
votes

I'm not sure why your code doesn't work but I always use an associative array for the fields and it works fine:

$fields = array(
  'role1' => $form_state['values']['role1'],
  'role2' => $form_state['values']['role2'],
  'role3' => $form_state['values']['role3'],
);

db_update('menu_custom')
  ->fields($fields)
  ->condition('title', $form_state['values']['title'])
  ->execute();