Last updated January 16, 2011. Created by LeeHunter on January 19, 2009.
Edited by jn2. Log in to edit this page.
This section will include tutorials and other information that you will need to create modules for Drupal version 7.x. As Drupal 7.x has just been released, the information here is currently limited.
Comments
submit button click then save into database
<?php
// $Id$
/**
* @file
* Convert ounces to milliliters
*/
/**
* Implementation of hook_menu()
*/
function ounces_to_ml_menu() {
$items = array();
$items['convert'] = array(
'title' => 'Converts ounces to milliliters',
'page callback' => 'ounces_to_ml_page',
'access arguments' => array('view content'),
);
return $items;
}
function ounces_to_ml_form($form, &$form_state) {
$form['ounces'] = array(
'#type' => 'textfield',
'#title' => t('Ounces'),
'#description' => t('The numbeor of ounces to convert to milliliters')
);
// $form['name'] = array(
// '#type' => 'textfield',
// '#title' => t('Name')
//
// );
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Convert')
);
return $form;
}
function ounces_to_ml_page() {
return drupal_get_form('ounces_to_ml_form');
}
function ounces_to_ml_form_submit($form, &$form_state) {
$output = $form_state['values']['ounces'];
db_query("INSERT INTO table_name (convert_val) VALUES ('$output') ")
->execute();
drupal_set_message($output);
}
?>
But problem is two times insert into table. Please help me
Two times insert problem
db_query will not used. example
$output = $form_state['values']['ounces'];$nid = db_insert('restaurant') // Table name no longer restaurant{}
->fields(array(
'restaurant_name' => $output))
->execute();
drupal_set_message($output);