thefortrees Posted June 5, 2007 Share Posted June 5, 2007 Alright - so, I have been trying to get this working all afternoon. I am writing a script to process a huge survey and store the form values in a database. EVERYTHING works but this one array (from HTML form). I'm sure it is a small problem. Any help is appreciated!! Here is the error (I echo other arrays to test that my loop works properly before and after the one with the problem, as can be seen by the printed values.): Web Developers Client Services Database Developers Web Developers Marketing Consulting Database Developers Warning: Invalid argument supplied for foreach() in /export/home/sevanet/twright/public_html/clientsurvey/temp/survey_handler.php on line 44 Useful Timely Interesting Informative Useful Interesting Informative -------------------------------------------------------------------- Here is the HTML code for the field (checkboxes) that is causing the problems: <div class="field"> <label for="uname">(Select as many as apply.) <em></em> </label> <ul> <li><input type="checkbox" name="choose_vectec[]" value="Training">Training</li> <li><input type="checkbox" name="choose_vectec[]" value="Superior Services">Superior Services</li> <li><input type="checkbox" name="choose_vectec[]" value="One on one consulting">One on one consulting</li> <li><input type="checkbox" name="choose_vectec[]" value="Reliability">Reliability</li> <li><input type="checkbox" name="choose_vectec[]" value="Operations Analysis">Operations Analysis</li> <li><input type="checkbox" name="choose_vectec[]" value="Cost">Cost</li> <li><input type="checkbox" name="choose_vectec[]" value="Continuing Education">Continuing Education</li> <li><input type="checkbox" name="choose_vectec[]" value="Private sector services not available">Private sector services not available</li> <li><input type="checkbox" name="choose_vectec[]" value="Private sector services not good">Private sector services not good</li> </ul> </div> ----------------------------------------------------------------------------------- And here is the PHP code from line 44 that processes each array in the form, but only has an error when it reaches ($key == 'choose_vectec'): foreach($_POST as $key => $value){ $passcode = $_COOKIE['passcode']; $user = $_POST['user']; $answer = $value; if ( ($key == 'received_service') || ($key == 'available_sector') || ($key == 'choose_vectec') || ($key == 'use_pensoft2') || ($key == 'use_ctdi2') ){ foreach($_POST[$key] as $values){ $answer .= $values . ' '; $search = "Array"; $replace = ""; $answer = str_replace($search, $replace, $answer); } //echo $answer; } $query = "INSERT INTO answers (passcode, user, questionID, answer) VALUES ('$passcode', '$user', '$qid', '$answer');"; mysql_query($query); $qid++; } Quote Link to comment Share on other sites More sharing options...
Barand Posted June 5, 2007 Share Posted June 5, 2007 try echo '<pre>', print_r($_POST, true), '</pre>'; and see if there are any clues in the posted values. Quote Link to comment Share on other sites More sharing options...
thefortrees Posted June 5, 2007 Author Share Posted June 5, 2007 Thanks for the help - never knew you could do that. But anyway, I just came home from work and tried it on my computer at home... works here.... haha - didnt change anything. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.