Mysql Drupal 7表单插入(如果已存在)显示消息(如已存在)

Mysql Drupal 7表单插入(如果已存在)显示消息(如已存在),mysql,drupal,Mysql,Drupal,bu使用druapl 7表格,我正在插入和显示日期,编辑和删除以及所有工作正常。。 现在我想..当插入表单时,我们需要显示消息,如果已经存档存在,国家名称已经像那样 不需要更新查询,仅在插入值检查时查询是否存在 因为下面的代码是通过传递参数来使用或编辑的 function countries_form($form, &$form_state,$id=0) { if($id!=0){ $result = db_query('SELECT * FROM {countries} WHER

bu使用druapl 7表格,我正在插入和显示日期,编辑和删除以及所有工作正常。。 现在我想..当插入表单时,我们需要显示消息,如果已经存档存在,国家名称已经像那样

不需要更新查询,仅在插入值检查时查询是否存在

因为下面的代码是通过传递参数来使用或编辑的

function countries_form($form, &$form_state,$id=0) {

if($id!=0){
 $result =  db_query('SELECT * FROM {countries} WHERE id = '.$id.'')->fetch();
// print_r($result);exit;

 $form['country_name'] = array(
    '#type' => 'textfield', //you can find a list of available types in the form api
    '#title' => 'Country name',
    '#size' => 30,
    '#maxlength' => 30,
    '#default_value' => $result->country_name,
    '#required' => TRUE, //make this field required 
  );
  $form['description'] = array(
    '#type' => 'textarea', //you can find a list of available types in the form api
    '#title' => 'Description',
    '#default_value' => $result->description,
    '#required' => TRUE, //make this field required 
  );
  $form['status'] = array(
  '#type' => 'radios',
  '#title' => t('Status'),
  '#default_value' => $result->status,
  '#options' => array(
    '1' => t('Active'),
    '0' => t('Inactive'),

  ),
  );

  }else{
  $form['country_name'] = array(
    '#type' => 'textfield', //you can find a list of available types in the form api
    '#title' => 'Country name',
    '#size' => 30,
    '#maxlength' => 30,
    '#required' => TRUE, //make this field required 
  );
 $form['description'] = array(
    '#type' => 'textarea', //you can find a list of available types in the form api
    '#title' => 'Description',
    '#required' => TRUE, //make this field required 
  );
  }
  $form['submit_button'] = array(
    '#type' => 'submit',
    '#value' => t('Click Here!'),
  );

  return $form;
}

function countries_form_submit($form, &$form_state) {
//$result =  db_query('SELECT country_name FROM {countries}')->fetch(); 
//print_r($result);
if(arg(2)!=0){

  $query = db_update('countries')->fields(array('country_name'=>$form_state['values']['country_name'],'description'=>$form_state['values']['description'],'status'=>$form_state['values']['status']))->condition('id',arg(2));

  $query->execute();
   // print_r($query); 
  drupal_set_message(t('Country %name has been updated.', array('%name' => $form_state['values']['country_name'])));

  //print_r($description);
  }else{
  //$query = db_update('countries')->fields(array('country_name'=>$form_state['values']['country_name'],'description'=>$form_state['values']['description'],'status'=>$form_state['values']['status']))->condition('country_name','%s');
 // print_r($query);

  $query = db_insert('countries')->fields(array('country_name'=>$form_state['values']['country_name'],'description'=>$form_state['values']['description']));
 //print_r($query);
  $query->execute(); 

  drupal_set_message(t('Country %name has been saved.', array('%name' => $form_state['values']['country_name'])));
  }

 //exit;
   $form_state['redirect'] = 'mypages/table';
  }

在此处插入的else代码中,我们需要检查天气是否存在

很抱歉,但您的文字很难阅读/理解。我的英语还远远不够完美,但这是…嗨,你能告诉我如何根据drupal 7Template中数据库的选择创建页面模板吗?页块查看?我将数据列为
    。现在我希望每个列表项都应该基于该url创建一个url。页面应该像drupal 7中的基本页面一样打开
    if(arg(2)!=0){
    
      $query = db_update('countries')->fields(array('country_name'=>$form_state['values']['country_name'],'description'=>$form_state['values']['description'],'status'=>$form_state['values']['status']))->condition('id',arg(2));
    
      $query->execute();
       // print_r($query); 
      drupal_set_message(t('Country %name has been updated.', array('%name' => $form_state['values']['country_name'])));
    
      //print_r($description);
      }else{