In a Drupal 7 custom module, I am updating a record in the database using a form, and I am using the following code to update, but for some reason it is not updating. Can anyone tell me why? I tried like 3 hours to change every possible thing but no luck.

function edit_job_form_submit($form, &$form_state){
  $id = $form_state['values']['id'];
  $job_title = $form_state['values']['job_title'];
  $description = $form_state['values']['description'];
  $cat_id = $form_state['values']['cat_id'];
  $job_type = $form_state['values']['job_type'];
  $company_id = $form_state['values']['company_id'];
  $description = $form_state['values']['description'];
  $location = $form_state['values']['location'];
  $Salary = $form_state['values']['Salary'];
  $benifits = $form_state['values']['benifits'];
  $Nationality = $form_state['values']['Nationality'];
  $Age = $form_state['values']['Age'];
  $join_date = $form_state['values']['join_date'];
  $date_added = date("y-m-d", time());

  $join_date_mod = gmdate('Y-m-d',strtotime($join_date));

  $num_updated = db_update('echelon_jobs')->fields(
      'job_title' => $job_title,
      'cat_id' => $cat_id,
      'job_type' => $job_type,
      'company_id' => $company_id,
      'location' => $location,
      'Salary' => $Salary,
      'benifits' => $benifits,
      'Nationality' => $Nationality,
      'Age' => $Age,
      'join_date' => $join_date_mod,
      'date_added' => $date_added,
  ->condition('id', $id)

  //dpq($num_updated, $name);
  drupal_set_message(t('Vacancy Updated Successfully..  '));
  • 1
    Get the SQL from the dpq() call, and run it against the database manually. That will tell you what the problem is.
    – Clive
    Commented Oct 3, 2013 at 10:08

1 Answer 1


As a matter of debugging, if you have the Devel module installed, try executing the query at devel/php with hard-coded data. That will help understanding if there is an issue with the db_update(). Also, when you run the query and an error occurs, the error log at admin/reports/dblog on your site should show you any error message about that query.

In case you need to update or insert values on a table, db_merge() should be used instead of db_update(). db_update() doesn't insert new rows, but updates the existing ones; db_merge() updates the existing ones, or creates new rows.

Once you are ready with a working query, debug the $form_state values; there might a mismatch between database table column type and the data you are trying to put there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.