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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.