Jump to content

[SOLVED] array processing - invalid argument


thefortrees

Recommended Posts

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++;

}

 

Link to comment
https://forums.phpfreaks.com/topic/54350-solved-array-processing-invalid-argument/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.