When i submit my code i get this warning:

Invalid argument supplied for foreach() in /home/a5909939/public_html/ordernow.php on line 262

Heres the code around it:

$Body .= "Ordertotal: ";
$Body .= $Ordertotal;
$Body .= "\n";
$body .= '--'.$boundary.$eol; 
$body .= 'Content-Type: text/plain; charset=iso-8859-1'.$eol; 
$body .= 'Content-Transfer-Encoding: 8bit'.$eol; 
$body .= $eol.stripslashes($message).$eol; 
foreach ($_FILES['userfile']['error'] as $i => $error) { 
  if ($error == 0 && $_FILES['userfile']['size'][$i] <= $max_size) { 
    $body .= '--'.$boundary.$eol; 
    $body .= 'Content-Type: '.$_FILES['userfile']['type'][$i].'; name='.$_FILES['userfile']['name'][$i].$eol; 
    $body .= 'Content-Transfer-Encoding: base64'.$eol; 
    $body .= 'Content-Disposition: attachment; filename='.$_FILES['userfile']['name'][$i].$eol; 
    $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES['userfile']['tmp_name'][$i]))).$eol; 
    $attached[] = $_FILES['userfile']['name'][$i]; 
  } 
} 

PLEASE SOMEBODY HELP! 😕 😕

    Apparently $FILES['userfile']['error'] isn't an array. Try doing a [man]print_r/man on $FILES to examine it's structure.

      When i use print_r() i get this:

      Warning: Invalid argument supplied for foreach() in /home/a5909939/public_html/ordernow.php on line 262
      
      
      Array ( ) Fatal Mail Error!
      

        $_FILES['userfile']['error'] would only be an array if the name of the input form element were named "userfile[]" (with the square brackets at the end of the name).

          that's what i named them

          <b>Pictures to be put on the page:</b><br>
          	  <input type="file" name="userfile[]"><br>
          	  <input type="file" name="userfile[]"><br>
          	  <input type="file" name="userfile[]"><br>
          	  <input type="file" name="userfile[]"><br>
          	  <input type="file" name="userfile[]"><br>
          	  <div id="morefiles6" class="hidden">
          	  <input type="file" name="userfile[]"><br>
          	  <input type="file" name="userfile[]"><br>
          	  <input type="file" name="userfile[]"><br>
          	  <input type="file" name="userfile[]"><br>
          	  <input type="file" name="userfile[]"><br>
          	  </div>
          

            Do you have the enctype="multipart/form-data" attribute in your <form> tag?

              Yes i have. But, does it matter that i have more than just file upload fields in that form and im trying to retrieve data from these with php to?

                gogole503 wrote:

                Yes i have. But, does it matter that i have more than just file upload fields in that form and im trying to retrieve data from these with php to?

                It should not matter, except I'm not sure what would happen if you used the same name for them, though.

                  do you have any idea how to make it work? Please help if u can! 😃

                    Since you are uploading as array of files, you'd actually need to do:

                    foreach($_FILES['userfile']['error'] as $key => $error)
                    {
                       print "Error for index $key: $error<br />\n";
                    }
                    

                      i did that and i just got the same error and:
                      fatal mail error

                        7 days later
                        gogole503 wrote:

                        i did that and i just got the same error and:
                        fatal mail error

                        I hate to be a b**** about it at this point, but dood, this is all part of learning php.

                        So now you have a fatal call when you call the built in mail function... so go to that part of the code and try and figure it out (basic debugging). If you still are stuck, try reference the mail function on the php.net page (that site if full of 90% of all your answers, I promise)!!!

                        Good luck!

                          Write a Reply...