Dont do a foreach on a non-array (if no questions were answered)

This commit is contained in:
james 2006-02-01 17:53:04 +00:00
parent b63674f649
commit d56f62f95e

View File

@ -74,16 +74,19 @@ echo mysql_error();
{ {
//first we will delete all their old answer, its easier to delete and re-insert in this case then it would be to find the corresponding answers and update them //first we will delete all their old answer, its easier to delete and re-insert in this case then it would be to find the corresponding answers and update them
mysql_query("DELETE FROM safety WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'"); mysql_query("DELETE FROM safety WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'");
$safetyids=array_keys($_POST['safety']); if(is_array($_POST['safety']))
foreach($safetyids AS $key=>$val)
{ {
mysql_query("INSERT INTO safety (registrations_id,safetyquestions_id,year,answer) VALUES (". $safetyids=array_keys($_POST['safety']);
"'".$_SESSION['registration_id']."', ". foreach($safetyids AS $key=>$val)
"'$val', ". {
"'".$config['FAIRYEAR']."', ". mysql_query("INSERT INTO safety (registrations_id,safetyquestions_id,year,answer) VALUES (".
"'".mysql_escape_string(stripslashes($_POST['safety'][$val]))."')"); "'".$_SESSION['registration_id']."', ".
echo mysql_error(); "'$val', ".
"'".$config['FAIRYEAR']."', ".
"'".mysql_escape_string(stripslashes($_POST['safety'][$val]))."')");
echo mysql_error();
}
} }
} }
} }