1

I am stuck on trying to make this work, I have a html form that has file and text inputs, after submission I want to process these inputs through a loop in my php script. Currently the loop skips the file input and processes only the text inputs. I am new at php, and I cant seem to understand what is wrong and how to fix it. Here is the form code and the php code to process it.

<form action='loop.php' enctype="multipart/form-data" data-ajax="false" method="POST">
     <input type ="text" name ="Input1"/>
     <input type ="file" name ="Input2"/>
     <input type ="text" name ="Input3"/>
     <input type ="text" name ="Input4"/>
     <input type='submit' data-corners="false" value ='submit'/>
</form>

loop.php

<?php
    foreach ($_POST as $key => $value){
         if($_POST[Input2]) //check if its the file input
         {//some manipulation on the file}
         else
         //process all other text inputs}
?> 

Thanks for your help

2
  • files are in $_FILES, and posted data is in $_POST. Commented Jul 21, 2013 at 19:10
  • I did not know that... Thanks. Using $_FILES i am now able to access the files Commented Jul 21, 2013 at 19:26

1 Answer 1

1
  1. $_POST[Input2] is wrong, but it should work. That's because Input2 is recognized as constant, not as string (what it should be). Change that into $_POST['Input2'] (see also PHP manual).
  2. You haven't closed some of the brackets. Pay attention to the legibility of your code to avoid this!
  3. $_POST[Input2] doesn't check if the currently processed input is Input2. You should do this with $key.
Sign up to request clarification or add additional context in comments.

1 Comment

Currently the loop skips the file input and processes only the text inputs. This is an issue with $_FILES[], not an issue with his input constants. Good effort, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.