From d56f62f95e10c715663c800dba12b216ab95e0ce Mon Sep 17 00:00:00 2001 From: james Date: Wed, 1 Feb 2006 17:53:04 +0000 Subject: [PATCH] Dont do a foreach on a non-array (if no questions were answered) --- register_participants_safety.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/register_participants_safety.php b/register_participants_safety.php index 289b179..0e98319 100644 --- a/register_participants_safety.php +++ b/register_participants_safety.php @@ -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 mysql_query("DELETE FROM safety WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'"); - $safetyids=array_keys($_POST['safety']); - foreach($safetyids AS $key=>$val) + if(is_array($_POST['safety'])) { - mysql_query("INSERT INTO safety (registrations_id,safetyquestions_id,year,answer) VALUES (". - "'".$_SESSION['registration_id']."', ". - "'$val', ". - "'".$config['FAIRYEAR']."', ". - "'".mysql_escape_string(stripslashes($_POST['safety'][$val]))."')"); - echo mysql_error(); + $safetyids=array_keys($_POST['safety']); + foreach($safetyids AS $key=>$val) + { + mysql_query("INSERT INTO safety (registrations_id,safetyquestions_id,year,answer) VALUES (". + "'".$_SESSION['registration_id']."', ". + "'$val', ". + "'".$config['FAIRYEAR']."', ". + "'".mysql_escape_string(stripslashes($_POST['safety'][$val]))."')"); + echo mysql_error(); + } } } }