Make sure your submit buttons (ie. <input type="submit"> etc) have a 'value' attribute. If they don't, the value won't appear in $_POST and so isset($_POST["submit"]) won't work either.
Example:
<input type="submit" name="submit">
isset($_POST["submit"]) returns false
<input type="submit" name="submit" value="Next">
isset($_POST["submit"]) returns true.
This might seem obvious for text buttons since they need a label anyway. However, if you are using image buttons, it might not occur to you that you need to set a value attribute as well. For example, the value attribute is required in the following element if you want to be able to detect it in your script.
<input type="image" name="submit" src="next.gif" value="Next">
$_POST
$HTTP_POST_VARS [deprecated]
$_POST -- $HTTP_POST_VARS [deprecated] — HTTP POST variables
Descrierea
An associative array of variables passed to the current script via the HTTP POST method.
$HTTP_POST_VARS contains the same initial information, but is not a superglobal. (Note that $HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)
Istoria schimbărilor
| Versiunea | Descriere |
|---|---|
| 4.1.0 | Introduced $_POST that deprecated $HTTP_POST_VARS. |
Exemple
Example #1 $_POST example
<?php
echo 'Hello ' . htmlspecialchars($_POST["name"]) . '!';
?>
Assuming the user POSTed name=Hannes
Exemplul de mai sus va afişa ceva similar cu:
Hello Hannes!
Note
Notă: Aceasta este o variabilă 'superglobală', sau globală automată. Aceasta pur şi simplu înseamnă că ea este disponibilă în toate circumstanţele pe parcursul script-ului. Nu este nevoie de a scrie global $variable; pentru a o accesa din funcţii sau metode.
$_POST
php dot net at bigbadaboom dot net
15-Jul-2008 01:06
15-Jul-2008 01:06
paul dot chubb at abs dot gov dot au
19-Jun-2008 04:49
19-Jun-2008 04:49
Nasty bug in IE6, Apache2 and mod_auth_sspi. Essentially if the user presses the submit button too quickly, $_POST (and the equivalents) comes back empty. The workaround is to set Apache's KeepAliveTimeout to 1. This would mean that the user would need to push submit within a second to trigger the issue.
telconstar99 at hotnospampleasemail dot com
19-May-2008 05:49
19-May-2008 05:49
<?
//If we submitted the form
if(isset($_POST['submitMe']))
{
echo("Hello, " . $_POST['name'] . ", we submitted your form!");
}
//If we haven't submitted the form
else
{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<input type="text" name="name"><br>
<input type="submit" value="submit" name="submitMe">
</form>
<?
}
?>
