I have to admit that I am a little lost on how to create a form then create a database record with the contents of the form. Hee is what I have created:

function poker_adminl() {
$form['league_add'] = array('#type' => 'fieldset', '#title' => t('Create a new poker league'));
$form['league_add']['league_name'] = array('#type' => 'textfield', '#title' => t('League Name'), '#maxlength' => 30 );
$form['league_add']['league_description'] = array('#type' => 'textfield', '#title' => t('Description'), '#maxlength' => 30 );

$edit = $_POST['edit'];
db_query("INSERT INTO {poker_leagues} (name, description) VALUES ('%s', '%s')", $edit['league_name'], $edit['league_description']);

return system_settings_form('poker_league_settings', $form);
}

I am sure there are all sorts of problems, but this code generates no errors. What it does though is create 3 database records. First a blank record, then a record with the form data, then another blank record.

Can anyone tell me what I am doing wrong?

Thanks in advance

Norm

Comments

nevets’s picture

Change your code to see if $edit is set, something like this

<?php
function poker_adminl() {

$edit = $_POST['edit'];

if ( $edit ) {
  db_query("INSERT INTO {poker_leagues} (name, description)   VALUES ('%s', '%s')", $edit['league_name'], $edit['league_description']);
}

$form['league_add'] = array('#type' => 'fieldset', '#title' => t('Create a new poker league'));
$form['league_add']['league_name'] = array('#type' => 'textfield', '#title' => t('League Name'), '#maxlength' => 30 );
$form['league_add']['league_description'] = array('#type' => 'textfield', '#title' => t('Description'), '#maxlength' => 30 );

return system_settings_form('poker_league_settings', $form);
}
?>
npollock’s picture

That worked, I really appreciate it. I have just a few more hurdles to go.

Thanks

Norm