title: AJAX Error Drupal-7
body: <p>I am creating a module in which there is a dependency between combo boxes. There are three combo boxes: country, state, and district. If I select India in the country combo box, then the state combo box will contain all states of India, and the same in the case of district.</p>
  
  <p>I have done this by using AJAX. It works properly in add form, but when I am going to update any one, the following error occurs:</p>
  
  <pre><code>An AJAX HTTP error occurred.
  HTTP Result Code: 500
  Debugging information follows.
  Path: /drupal/?q=system/ajax
  StatusText: Service unavailable (with message)
  ResponseText: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ajax' in 'where clause': SELECT district_name, country_id,state_id FROM {ajax_district} where id = ajax; Array
  (
  )
  in edit_district_form() (line 291 of /home/mansmu/www/drupal/sites/default/modules/ajaxtest/ajaxtest.district.inc).
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>////////////////////////////////////////////////////////
  ///////// FUNCTION FOR EDIT
  ////////////////////////////////////////////////////////
  function edit_district_form($form, &amp;$form_state) {
  $request_url = request_uri();
  // $request_id to get id of edit district.
  $request_id = drupal_substr(strrchr($request_url, '/'), 1);
  
  //// FOR country
  $rows = array();
  $result = db_query("SELECT id,country_name from {ajax_country} order by country_name");
  while ($data = $result-&gt;fetchObject()) {
  $id = $data-&gt;id;
  $rows[$id] = $data-&gt;country_name;
  }
  
  //// FOR state
  $state = array();
  $result = db_query("SELECT id,state_name from {ajax_state} order by state_name");
  while ($data = $result-&gt;fetchObject()) {
  $id = $data-&gt;id;
  $state[$id] = $data-&gt;state_name;
  }
  
  // $district_name varible to get name from database for a requested id.
  $district_name = db_query("SELECT district_name, country_id,state_id FROM {ajax_district} where id = ".$request_id);
  // Loop For show vehicle district name in text field to be update.
  foreach ($district_name as $district) {*/
  $form['values']['edit_country_name'] = array(
  '#type' =&gt; 'select',
  // '#default_value' =&gt; "{$district-&gt;country_id}",
  '#required' =&gt; TRUE,
  '#options' =&gt; $rows,
  '#ajax' =&gt; array(
  'effect' =&gt; 'fade',
  'progress' =&gt; array('type' =&gt; 'none'),
  'callback' =&gt; 'state_callback_edit',
  'wrapper' =&gt; 'replace_edit_state',
  ),
  );
  
  $form['values']['edit_state_name'] = array(
  '#type' =&gt; 'select',
  // '#default_value' =&gt; "{$district-&gt;state_id}",
  '#required' =&gt; TRUE,
  '#options' =&gt; array(),
  // The prefix/suffix provide the div that we're replacing, named by #ajax['wrapper'] above.
  '#prefix' =&gt; '',
  '#suffix' =&gt; '',
  );
  
  $form['values']['edit_district_name'] = array(
  '#type' =&gt; 'textfield',
  '#size' =&gt; 30,
  //'#default_value' =&gt; "{$district-&gt;district_name}",
  '#maxlength' =&gt; 80,
  '#required' =&gt; TRUE,
  );
  }
  
  $form['edit_district_submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Update'),
  );
  $form['actions']['cancel'] = array(
  '#markup' =&gt; l(t('Cancel'), 'district'),
  );
  
  return $form;
  }
  </code></pre>
  
  
  
  <pre><code>////////////////////////////////////////////////////////
  ///////// FUNCTION FOR AJAX CALL BACK
  ////////////////////////////////////////////////////////
  function state_callback_edit($form, &amp;$form_state) {
  // An AJAX request calls the form builder function for every change.
  // We can change how we build the form based on $form_state.
  if (!empty($form_state['values']['edit_country_name'])) {
  $country_id = $form_state['values']['edit_country_name'];
  $rows1 = array();
  $result = db_query("SELECT id, state_name from {ajax_state} where country_id = $country_id order by state_name");
  while ($data = $result-&gt;fetchObject()) {
  $id = $data-&gt;id;
  $rows1[$id] = $data-&gt;state_name;
  }
  $form['edit_state_name']['#options'] = $rows1;
  }
  return $form['values']['edit_state_name'];
  }
  </code></pre>