Oh, we're so close now I can smell it! 🙂
Your:
foreach ($sfn as $value) {
if (isset($_POST[$value])) {
$$value = $_POST[$value];
} else {
$$value = '';
}
}
with the help of:
echo '<pre>';
print_r($_POST);
echo '</pre>';
$headers = implode (",", $sfn);
$inputs = "'" . implode ("','", $_POST) . "'";
echo '<pre>';
print_r($headers.'<P>'.$inputs);
echo '</pre>';
spit out:
Array
(
[lg_initials] => kjghg
[lg_full_name] => gchgchg
[site_address] =>
[email_address] =>
[commissioner_real_name] =>
[commissioner_nick_name] =>
[participants] => Solo
[membership_fee] =>
[export_deadlines] =>
[sim_period] =>
[teams] =>
[ratings_scales] =>
[evaluation_weights] =>
[era] =>
[modifiers] =>
[payroll_cap] =>
[first_season] =>
[current_season] =>
[date_established] =>
[third_party] =>
[additional_info] =>
[password] =>
)
lg_initials,lg_full_name,defunct,site_address,email_address,commissioner_real_name,commissioner_nick_name,participants,role_played,openings,game_version,game_needed,membership_fee,export_deadlines,sim_period,players,teams,development,coaches_scouts,ratings_scales,evaluation_weights,era,modifiers,financials,payroll_cap,first_season,current_season,date_established,third_party,additional_info,password
'kjghg','gchgchg','','','','','Solo','','','','','','','','','','','','','','',''
(defunct and participants are two of those radio options.)
So that didn't quite work as still many of the inputs, including defunct, are still missing from the $_POST array.
But rearranging your code to:
foreach ($sfn as $value) {
if (!isset($_POST[$value])) {
$_POST[$value] = 'NULL';
}
$$value = $_POST[$value];
}
(I believe 'NULL' is as good as '' for my purposes, but easier to pick out for now.)
spits out:
Array
(
[lg_initials] => kjghg
[lg_full_name] => gchgchg
[site_address] =>
[email_address] =>
[commissioner_real_name] =>
[commissioner_nick_name] =>
[participants] => Solo
[membership_fee] =>
[export_deadlines] =>
[sim_period] =>
[teams] =>
[ratings_scales] =>
[evaluation_weights] =>
[era] =>
[modifiers] =>
[payroll_cap] =>
[first_season] =>
[current_season] =>
[date_established] =>
[third_party] =>
[additional_info] =>
[password] =>
[defunct] => NULL
[role_played] => NULL
[openings] => NULL
[game_version] => NULL
[game_needed] => NULL
[players] => NULL
[development] => NULL
[coaches_scouts] => NULL
[financials] => NULL
)
lg_initials,lg_full_name,defunct,site_address,email_address,commissioner_real_name,commissioner_nick_name,participants,role_played,openings,game_version,game_needed,membership_fee,export_deadlines,sim_period,players,teams,development,coaches_scouts,ratings_scales,evaluation_weights,era,modifiers,financials,payroll_cap,first_season,current_season,date_established,third_party,additional_info,password
'kjghg','gchgchg','','','','','Solo','','','','','','','','','','','','','','','','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL'
which is oh so close to what we want, except for one problem. See how in the bottom line 'Solo' is the seventh input? Well, if you look at the second to last line, it's actually supposed to be the eighth, as 'participants' (the key for the value Solo) is the eighth header. So what's happening is it's trying to insert the value 'Solo' into the 'commissioner_nick_name' column when it's supposed to be in the 'participants' column. The reason why is because no option for defunct was selected so the defunct key got a null value, but it was pushed to the bottom of the $_POST array, which caused everything after it, including participants, to be pushed up one slot.
How can I make it so that it will retain the order it should have? That is, how can I get:
'kjghg','gchgchg','','','','','Solo','','','','','','','','','','','','','','','','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL'
to become:
'kjghg','gchgchg','NULL','','','','','Solo'...
? Notice how the NULL value for the defunct key was pushed up to the 3rd slot and 'Solo' was pushed to the 8th along with other slot arrangements past that? I could rearrange the form inputs, but I'd really rather not as there's a logical order to them for the user.