I\'m working on a page in PHP 5.3.5, and it seems that $_POST
doesn\'t contain the data submitted from my form.
This is the HTML file :
You have not POSTed, or something is clobbering $_POST
.
If you have no mention of $_POST
in your code before trying to access them, then you haven't POSTed to your script.
Here it worked, but in PHP 5.3.1. Try this:
<!doctype html>
<html>
<head>
<title>form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form method="post" action="process.php">
<fieldset><legend>your data</legend>
<input type="text" name="txtname" id="id_name" />
<input type="text" name="txtage" id="id_age" />
</fieldset>
<button type="submit">OK</button>
</form>
</body>
</html>
<?php
if(isset($_POST["txtname"]))
$txtname = $_POST["txtname"];
else
unset($txtname);
if(isset($_POST["txtage"]))
$txtage = $_POST["txtage"];
else
unset($txtname);
?>
<!doctype html>
<html>
<head>
<title>form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p>Welcome <?=$txtname; ?>!<br />
You are <?=$txtage; ?> years old.</p>
</body>
</html>
Try to use capitals in POST:
<form action="file.php" method="POST">
Instead of:
<form action="file.php" method="post">
It's probably because you have magic_quotes_gpc turned on. You should turn it off: http://www.php.net/manual/en/security.magicquotes.disabling.php
Try <?php var_dump($_POST); ?>
to see what's really in there. There's no way $_POST is broken - it's gonna be something else. Possibly a server setting could be disabling $_POST.
PHP 5.3 is moving away from using global, pre-set variables, like $_POST, to avoid vulnerabilities.
The issue, as I understand it, is that programmers who have never had to use $_POST or $_GET might treat it as any other variable and open themselves up to security threats.
I haven't discovered the "proper" way to retrieve $_POST data yet, but the method I've using seems fairly sanitary.
<?php parse_url(file_get_contents("php://input"), $_POST);
This transfers the parsed HTTP POST string to the $_POST variables