\db_insert
function
Returns a new InsertQuery object for the active database.

Returns a new InsertQuery object for the active database.

Comments

thhafner’s picture

Here is a quick example of inserting data from a custom form on form submission.

$conn = Database::getConnection();
$conn->insert('contact_form')->fields(
  array(
    'sender_name' => $form_state->getValue('name'),
    'sender_email' => $form_state->getValue('email'),
    'sender_subject' => $form_state->getValue('recipient'),
    'sender_message' => $form_state->getValue('message'),
  )
)->execute();
krishanchandra’s picture

This is helped me --- $form_state->getValue('name'),

imanoop’s picture

$Data = db_insert('table_name')
->fields(
array(
'fid' => $form_state->getValue('img')[0],
'name' => $form_state->getValue('client_title'),
'description' => $form_state->getValue('short_desc'),
'changed' => time(),
'status' => '1',
)
)->execute();

In your table default value should not be none.