-2

I searched internet and I could not find a solution for the problem. I have a form and when I submit only text fields there is no problem. But when I add file input and submit the form I get undefined index error.

HTML CODE

    <form method="post" action="add.php" enctype="multipart/form-data">
        <input type="hidden" name="MAX_FILE_SIZE" value="10485760">
        <input type="text" name="topic" style="width:300px;" value="cars" />        
        <input type="file" name="file1" id="file1" />
        <input type="submit" name="submit" value="Add"/>
    </form> 

PHP CODE

if(isset($_POST['submit']))
{
    // Form
}
else echo'NOOO';

This code always give NOOO when uploading file. I have controlled php.ini and upload is on.

8
  • 5
    did you add enctype="multipart/form-data" in form tag?? Commented Sep 29, 2015 at 12:46
  • 1
    pleas post the complete form HTML Commented Sep 29, 2015 at 12:48
  • are you adding the if(isset($_POST['submit'])) code to add.php? Because, your form is submitted there. Commented Sep 29, 2015 at 12:49
  • possible duplicate of How to fix 'Notice: Undefined index:' in PHP form action? Commented Sep 29, 2015 at 12:51
  • 2
    you need to use $_FILES to obtain any file requests. However, the way you have it set up. It should work. What problems are you having exactly? Commented Sep 29, 2015 at 12:51

1 Answer 1

0

Not every Browser sends the Submit button Value

you should check for your real Input values

if(isset($_POST['topic']))
{
    // Form
}
else echo'NOOO';

if you want to check if your File is attched

use

$_FILE['file1'] 

instead of $_POST

Sign up to request clarification or add additional context in comments.

6 Comments

You should point out the browsers that do not send the "submit" value so that we can test
My browser is Microsoft Edge. It give same error with Chrome. if(isset($_POST['submit'])) worked when using only text field but not working after added file field.
What do you mean by "...but not working after added file field." ?
Is that same error happening when you use a different browser?
Edit your initial question and include all your code because its obviously something else youre not telling or showing us.
|

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.