I should add that your form input names can be taken directly from the database tables you plan on inserting the form data into. You don't hard-code your input field names, so that if you change your database schema, your form is automatically aware of the change. This also lets you
generate your INSERT and UPDATE queries by using your form input names. For example:
$add_slashes = (0 == get_magic_quotes_gpc());
foreach ($_POST['some_form'] as $input_name => $input_value)
{
$columns[] = $input_name;
$values[] = "'" . ($add_slashes? addslashes($input_value) : $input_value) . "'";
}
$colstr = join(', ', $columns);
$valstr = join(', ', $values);
$query = "INSERT INTO table_name ({$colstr}) VALUES ({$valstr})";
Keep in mind this works for simple schemas where each form's inputs corresponds with the columns in a single table. If you're going to have to insert into multiple tables (or assemble the form from multiple tables), it kind of falls apart.
For this reason, though, I recommend using wrapper functions to encapsulate this functionality -- have a function generate your column names. Have a function perform the insert queries. That way, should your schema become more complicated (read: multiple tables), you can just modify the contents of those functions and the rest of your script doesn't have to know or care about those changes. It still calls the function.
Take care,
Nik
http://www.bigaction.org/