$ _POST in php 5.3.5 not working

I am working on a page in PHP 5.3.5 and it seems that $_POST does not contain the data presented in my form.

This is the HTML file:

 <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> 

And this is the PHP file:

 <html> <body> Welcome <?php echo $_POST["fname"]; ?>!<br /> You are <?php echo $_POST["age"]; ?> years old. </body> </html> 

The problem is that form values ​​are not passed, so I get the output as follows:

  Welcome!
 You are years old.

Instead of this:

  Welcome John!
 You are 28 years old.

What am I doing wrong?

+2
source share
10 answers

Try <?php var_dump($_POST); ?> <?php var_dump($_POST); ?> to see what is really there. There cannot be broken $ _POST - it will be something else. Perhaps server installation might disable $ _POST.

+5
source

Probably because you have magic_quotes_gpc enabled. You must disable it: http://www.php.net/manual/en/security.magicquotes.disabling.php

+2
source

PHP 5.3 is moving away from using global predefined variables such as $ _POST to avoid vulnerabilities.

The problem, as I understand it, is that programmers who have never had to use $ _POST or $ _GET could treat it like any other variable and open themselves up to security risks.

I have not yet discovered the “right” way to get $ _POST data, but the method I use seems pretty sanitary.

 <?php parse_url(file_get_contents("php://input"), $_POST); 

This transfers the parsed HTTP POST string to the $ _POST variables

+2
source

Are you checking your php.ini?
I broke my mail method when I set post_max_size the same with upload_max_filesize .

I think post_max_size should be less than upload_max_filesize .
Tested with PHP 5.3.3 on RHEL 6.0

+2
source

Is your HTML form method used for POST ?

 <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> 
0
source

You don't have POSTed, or something is hiding $_POST .

Unless you mention $_POST in your code, before trying to access them, you have not sent POST to your script.

0
source

Here it worked, but in PHP 5.3.1. Try the following:

 <!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> 
0
source
0
source

Try using capitals in POST:

 <form action="file.php" method="POST"> 

Instead:

 <form action="file.php" method="POST"> 
0
source

I also had the same problem. I used Windows notepad to edit the .php file and accidentally saved the file in Unicode, and this created a problem. Then I saved it in UTF-8 encoding and it worked like a charm. Hope this helps.

0
source

All Articles