I have the following code sample upload3.php:
<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 does this happen? Because the same script upload3.php calls itself?
Definition and Usage. The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL. This function returns true if the variable exists and is not NULL, otherwise it returns false.
Use isset() method in PHP to test the form is submitted successfully or not. In the code, use isset() function to check $_POST['submit'] method. Remember in place of submit define the name of submit button. After clicking on submit button this action will work as POST method.
to check if your script was POSTed. If additional data was passed, $_POST will not be empty, otherwise it will. You can use empty method to check if it contains data. Since $_POST always exists if ($_POST) will do just fine, no need for empty .
You do not have your submit button named:
Change
<input type='submit' value='Upload' />
To:
<input type='submit' value='Upload' name="submit"/>
Two things:
You'll want to try array_key_exists instead of isset when using arrays. PHP can have some hinky 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)) { }
Second, you need a name attribute on your button ( "name='submit'" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With