I’m making a survey system and I’ve got a form with a list of answer values. (This part of the program takes and adds the answer types that are available, which, when creating the survey creation form, will be pulled from the db.) Now I want to take those answer values and stick them in one table and then take the other parts and stick them in another table. Problem is, I’m not sure how to get the values out of the array so that I’m not entering blank information into the db. I went to see if my server had mysql 5, but it does not, because if it had I would just convert the database to myisam and then run a trigger to see if there was any data posted into the db after it was posted. A shite way to do it, but it would have sufficed. So basically, how can I recursively go through multiple arrays to determine if the data is there, and if it is put it into the database, piece by piece? Here’s the code I’ve got thus far – with the stuff that’s not needed taken out: [code] <?php if((isset($_POST['AddAnswer'])) && ($_POST['AddAnswer'] == 'Add Answer')){ $SurveyID = $_POST['SurveyID']; $AnswerName = $_POST['AnswerName']; $AnswerType = $_POST['AnsTypes']; $Label = $_POST['Label']; //EXPLODES THE HIDDEN ANSWER FIELD INTO AN ARRAY SO WE CAN CHECK TO SEE IF THE VARIABLES EXIST //$answer_value = explode(",", $_POST['AnswerChecker']); $answer_value = $_POST['AnswerChecker']; //EXPLODES THE HIDDEN NUMERIC FIELD INTO AN ARRAY SO WE CAN CHECK TO SEE IF THE VARIABLES EXIST $numeric_value = explode(",", $_POST['NumericChecker']); //EXPLODES THE HIDDEN IMAGE FIELD INTO AN ARRAY SO WE CAN CHECK TO SEE IF THE VARIABLES EXIST $image_value = explode(",", $_POST['ImageChecker']); $count = 0; //COUNTER TO DETERMINE HOW MANY ROWS HAD VALUES foreach($answer_value as $ans_field){ foreach($numeric_value as $num_field){ foreach($image_value as $img_field){ if($_POST[$ans_field] != ""){ $AnsVal = $_POST[$ans_field]; $NumVal = $_POST[$num_field]; $ImgVal = $_POST[$img_field]; $add_value_sql = "INSERT INTO answer_values (answer_id, answer_value, numeric_value, image) VALUES ('$AnswerID', '$AnsVal', '$NumVal', '$ImgVal')"; $addvalue_result = mysql_query($add_value_sql, $connection) or die(mysql_error()); $count++; } } } } //CREATES THE SQL QUERY $add_answer_sql = "INSERT INTO answer_types (survey_id, answer_name, answer_type, label) VALUES ('$SurveyID', '$AnswerName', '$AnswerType', '$Label')"; $add_answer_result = mysql_query($add_answer_sql, $connection) or die(mysql_error()); } ?> <fieldset><legend>Add Answers</legend> <form method="post" name="AddAnswer" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <dl> <dt>*Survey Name:</dt> <dd><select name="SurveyID"> <?php do { ?><option value="<?php echo $row_Available_Surveys['survey_id']?>" ><?php echo $row_Available_Surveys['survey_name']?></option> <?php } while ($row_Available_Surveys = mysql_fetch_assoc($Available_Surveys)); ?> </select></dd> <dt>Answer Name:</dt> <dd><input type="text" name="AnswerName" size="32" /></dd> <dt>**Label:</dt> <dd><input type="text" name="Label" size="32" /></dd> <dt>Answer Type:</dt> <dd><select name="AnsTypes"> <?php do { ?><option value="<?php echo $row_Available_Answer_Types['answer_type_id']?>" ><?php echo $row_Available_Answer_Types['answer_type']?></option> <?php } while ($row_Available_Answer_Types = mysql_fetch_assoc($Available_Answer_Types)); ?></select></dd> </dl> <table> <tr> <td>Active</td> <td>Num</td> <td>Answer Value(Displayed)</td> <td>Numeric Value</td> <td>Image</td> </tr> <?php for ($j = 1; $j <= 6; $j++){ echo "<tr>\n"; echo "<td><input type='checkbox' name='active$j' checked='checked' /></td>"; echo "<td>$j.</td>\n"; echo "<td><input type='text' name='ans_val$j' size='32' /></td>\n"; echo "<td><input type='text' name='num_val$j' value='0' size='32' /></td>\n"; echo "<td><input type='text' name='img_val$j' value='default.jpg' size='32' /></td>\n"; echo "</tr>\n"; } ?> </table> <input type="hidden" name="ActiveAnsChecker" value="active1,active2,active3,active4,active5,active6" /> <input type="hidden" name="AnswerChecker" value="ans_val1,ans_val2,ans_val3,ans_val4,ans_val5,ans_val6" /> <input type="hidden" name="NumericChecker" value="num_val1,num_val2,num_val3,num_val4,num_val5,num_val6" /> <input type="hidden" name="ImageChecker" value="img_val1,img_val2,img_val3,img_val4,img_val5,img_val6" /> <input type="hidden" name="AnswerID" value="<?php echo $AnswerID ?>" /> <input type="submit" name="submit" value="Add Answer" /> <input type="hidden" name="AddAnswer" value="Add Answer" /> </form> </fieldset> [/code] Now I do realize that the nested foreach does not work, but it's what I had thought to do. When I tried doing it like that it added around 100 entries into the db. Not very efficient or workable. The hidden fields are a tad monotonous and unneeded. Especially the ActiveAnsChecker and the checkboxes, but I was trying to give myself more hooks to figure out what the hell to do. You'll also notice that the checkboxes or active_ans are not referenced in this code, but that's mostly because I'm not sure what I was trying to do with them. Thanks for any help. I appreciate it much!