0

This question already has an answer here:

$languages_knows=array(
'English' =>t('English'),
'Hindi' => t('Hindi'),
'Marathi' => t('Marathi')
 );

$form['languages_known'] = array(
'#title' => t('Language Spoken'),
'#options' => $languages_knows,
  '#type' => 'checkboxes'
);
function lawyer_register_form_submit($form, $form_state)
{
//Does something with successfully submited form fields.
global $user;
 $user = db_insert('lawyer_details')
->fields(array(
'first_name' => $form_state['values']['first_name'],
'middle_name' => $form_state['values']['middle_name'],
'last_name' => $form_state['values']['last_name'],
'languages_known'=>$form_state['values']['languages_known'],
))->execute();

Please help me.they gives error

PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: INSERT INTO {lawyer_details} (first_name, middle_name, last_name, street_address, city, country, phone, email_id, speciality, languages_known) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9);

marked as duplicate by kenorb, Shawn Conn, Adrian Cid Almaguer, Krishna Mohan, Neograph734 Jun 8 '16 at 9:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

'checkboxes' are array - serialize values on insert (and unserialize when get it), something as

'languages_known'=>serialize($form_state['values']['languages_known'])

edit:

full working code for example form

function mymodule_menu() {
  $items['test-form'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array('test_form'),
    'access callback' => TRUE,
  );

  return $items;
}

function test_form($form, &$form_state) {

  $languages_knows=array(
    'English' =>t('English'),
    'Hindi' => t('Hindi'),
    'Marathi' => t('Marathi')
  );

  $form['languages_known'] = array(
    '#title' => t('Language Spoken'),
    '#options' => $languages_knows,
    '#type' => 'checkboxes'
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  return $form;
}

function test_form_submit($form, &$form_state) {
  //Does something with successfully submited form fields.
  global $user;

  $user = db_insert('lawyer_details')
    ->fields(array(
      //'first_name' => $form_state['values']['first_name'],
      //'middle_name' => $form_state['values']['middle_name'],
      //'last_name' => $form_state['values']['last_name'],
      'languages_known'=>serialize($form_state['values']['languages_known']),
    ))->execute();
}

also you need to have install file, same as mymodule.install with table/field schema:

<?php

function mymodule_schema() {
  $schema['lawyer_details'] = array(
    'description' => 'Details comments here.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Some identifier.',
      ),
      'languages_known' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Some description here.',
      ),
    ),
    'primary key' => array('id'),
  );

  return $schema;
}

then delete your table, uninstall module (uncheck, save, uninstall) and install again.

test

hint: see https://www.drupal.org/node/159605 for schema field definition

  • if i want select all them so it is possible they insert all values using comma – Swapnil0226 Sep 30 '14 at 6:52
  • It gives me error when i select multiple languages – Swapnil0226 Sep 30 '14 at 7:00
  • column need to be varchar – svetlio Sep 30 '14 at 7:04
  • Yes, It is varchar(200) – Swapnil0226 Sep 30 '14 at 7:05
  • 1
    please help me i am not getting right answer.how i can inset multiple language into table field – Swapnil0226 Sep 30 '14 at 11:26

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