MrsTupid Posted March 16, 2009 Share Posted March 16, 2009 I have a form that is a survey which has a variable number of questions in it. There are two types of question in it, rating questions (under which a variable number of people are rated) and text questions. So for each rating question I need to insert into a table called FeedbackRating FeedbackID QuestionID passed through as RQuest (and then an incrementing number on the end) LecturerID passed through as LecsID (" same as above, eg first will be LecsID1, LecsID2...) RatingValue passed through as Rat (" same as above Rat1, Rat2, Rat3) So what I have created is this: ...... <?php $FeedbackID = mysql_insert_id(); # fetch the newly generated id $RatingQuests = array(); for($i=1;$i<=40;$i++) # create array with 1-40 elements if(isset($_POST['Rat'.$i]) and ($_POST['Rat'.$i] > "")) $RatingQuests[] = '('.$FeedbackID.',"'.($_POST['Rat'.$i]).'")'; $values = implode(',',$RatingQuests); $sql2 = "INSERT INTO FeedbackRating (FeedbackID,RatingValue) VALUES $values"; ?> What this does is cycle through all the Rat posts and inserts them all fine. However I can't work how how to expand this to do the RQuest and LecsID. I thought it might be something like this however it doesn't work <?php $FeedbackID = mysql_insert_id(); # fetch the newly generated id $RatingQuests = array(); for($i=1;$i<=40;$i++) # create array with 1-40 elements if(isset($_POST['RQuest'.$i]) and ($_POST['RQuest'.$i] > "")) && isset($_POST['LecsID'.$i]) and ($_POST['LecsID'.$i] > "")) && isset($_POST['Rat'.$i]) and ($_POST['Rat'.$i] > ""))) $RatingQuests[] = '('.$FeedbackID.',"'.($_POST['RQuest'.$i]).'","'.($_POST['LecsID'.$i]).'","'.($_POST['Rat'.$i]).'")'; $values = implode(',',$RatingQuests); $sql2 = "INSERT INTO FeedbackRating (FeedbackID,QuestionID,LecturerID,RatingValue) VALUES $values"; ?> Hope I have explained this well enough anyway. Any thoughts would be great Link to comment https://forums.phpfreaks.com/topic/149649-form-submission-array-handling/ Share on other sites More sharing options...
kickstart Posted March 16, 2009 Share Posted March 16, 2009 Hi Are QuestionID and LecturerID numeric fields? All the best Keith Link to comment https://forums.phpfreaks.com/topic/149649-form-submission-array-handling/#findComment-785823 Share on other sites More sharing options...
MrsTupid Posted March 16, 2009 Author Share Posted March 16, 2009 Hey, yes they are both numberic int(5) Link to comment https://forums.phpfreaks.com/topic/149649-form-submission-array-handling/#findComment-785826 Share on other sites More sharing options...
MrsTupid Posted March 16, 2009 Author Share Posted March 16, 2009 I should say RatingValue can either be text or numerical but QuestionID and LecturerID are always numerical Link to comment https://forums.phpfreaks.com/topic/149649-form-submission-array-handling/#findComment-785828 Share on other sites More sharing options...
kickstart Posted March 16, 2009 Share Posted March 16, 2009 Hi In which case you should take the inverted commas away that are around them $RatingQuests[] = '('.$FeedbackID.','.($_POST['RQuest'.$i]).','.($_POST['LecsID'.$i]).',"'.($_POST['Rat'.$i]).'")'; All the best Keith Link to comment https://forums.phpfreaks.com/topic/149649-form-submission-array-handling/#findComment-785982 Share on other sites More sharing options...
MrsTupid Posted March 16, 2009 Author Share Posted March 16, 2009 Ah ok thank you. is the IF statement I have a valid was of doing this? I don't actually know how to do multiple isset's at once.. if(isset($_POST['Rat'.$i]) and ($_POST['Rat'.$i] > "")) works but i don't know how to include many of them at a time.. Link to comment https://forums.phpfreaks.com/topic/149649-form-submission-array-handling/#findComment-786052 Share on other sites More sharing options...
kickstart Posted March 17, 2009 Share Posted March 17, 2009 Hi You have an odd set of mismatching brackets. Should be:- if(isset($_POST['RQuest'.$i]) and $_POST['RQuest'.$i] > "" and isset($_POST['LecsID'.$i]) and $_POST['LecsID'.$i] > "" and isset($_POST['Rat'.$i]) and $_POST['Rat'.$i] > "") All the best Keith Link to comment https://forums.phpfreaks.com/topic/149649-form-submission-array-handling/#findComment-786602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.