PHP loading - Why isset ($ _ POST ['submit']) is always FALSE

I have the following upload3.php code example:

<html> <head> <title>PHP Form Upload</title> </head> <body> <form method='post' action='upload3.php' enctype='multipart/form-data'> Select a File: <input type='file' name='filename' size='10' /> <input type='submit' value='Upload' /> </form> <?php if (isset($_POST['submit'])) { echo "isset submit"; } else { echo "NOT isset submit"; } ?> </body> </html> 

The code always returns "NOT isset submit". Why is this happening? Because the same script upload3.php calls itself?

+7
php
source share
5 answers

You do not have a submit button:
Change

 <input type='submit' value='Upload' /> 

To:

 <input type='submit' value='Upload' name="submit"/> 
+33
source share

Two things:

When using arrays, you will want to try array_key_exists instead of isset. PHP may have some weird behavior when using isset on an array element.

http://www.php.net/manual/en/function.array-key-exists.php

if (array_key_exists ('submit', $ _POST) {}

Secondly, you need the name attribute on your button ("name = 'submit'")

+4
source share

Since you do not have a form element, the name submit property.

Try using var_dump($_POST) to see the keys that are defined.

Note that files are an exception; they are not included in $_POST ; they are stored in the file system, and they are metadata (location, name, etc.) in the $_FILES .

+3
source share

Try a look at REQUEST_METHOD and see if it has a POST. This is a little better.

+2
source share
 <input type='submit' value='Upload' /> 

it should be

 <input type='submit' value='Upload' name='subname'/> 

and this name should be in $ _POST ['']

he will look like

 if (isset($_POST['subname'])) { echo "isset submit"; } else { echo "NOT isset submit"; } 
0
source share

All Articles