I've recently migrated servers and found that all $_POST requests on my website are no longer working. The requests always successfully redirect to the 'post' page, but no data is sent and print_r($_POST) always turns up an empty string. I believe this issue has something to do with PHP's settings because the problem occurs over multiple pages which were working fine on the previous server (GET requests seem to still be working fine).
I created a test.php file in my home directory with a very simple POST form to try to rule out any variables.
<?php print_r($_POST); ?>
<form action="test.php" method="POST">
Name: <input type="text" name="name"><br>
<input type="submit">
</form>
the page always prints only an empty the array Array ( )
Any help would be greatly appreciated, I'm sure its something simple but google doesn't seem to have the answer :(
I've realized the issue was in my .htaccess file. My POSTS were being stripped of their extensions and losing all the post data.
this topic php $_POST array empty upon form submission was the most help
Related
I have a form with one text input field:
index.html
<form method="post" action="comment.php">
<a href="javascript:void(0)">
<div class="avatar" style="background:url('img/user4561.jpg') center/cover"></div>
</a>
<input name="comm" type="text"/>
<input type="submit" value="submit"/>
</form>
And here is comment.php in the same directory
<?php
echo $_POST["comm"];
?>
Now the most incredible event. The form data does not get submitted! I get an error:
Notice: Undefined index: comm in 192.168.0.1/comment.php on line 2
I changed comment.php like this:
<?php
if(isset($_POST["comm"])) {
echo "It is set";
} else {
echo "It is not set";
}
?>
and I get:
It is not set
So, I copied the HTML code of the form into another blank webpage. I also changed the action attribute of the form to "192.168.0.1/comment.php". Now I get
It is set
I also tried using GET instead of POST, but I am again in the same conflict.
EDIT: I removed all other files and code, except for the form and its script. The problem persists. You can now read and modify the source code. Go to files.000webhost.com. Use chatstack as the website name and 6RxOkuJ1CIkbNqxKUMGr as the password.
EDIT: I modified the code for the form above to exactly match that in the above given link. I noticed that removing the link from inside the form solves the problem. I have already done this, but this is so weird. According to this post it is totally fine to have other elements inside a <form> element. There are also other parts of my website where I have <div> elements inside a form element and the form is working fine.
What is this? Is it the server or something else?
I am pretty sure the information provided here is not enough. Feel free to ask for any additional information. There is just too much information to write in a post, and I don't know which part of it is relevant.
Open your dev-console in browser.
Go to the network tab. Now you fill in your form and submit. After your comment.php is loaded, you check for the very first row in the network tab (should be the comment.php html document).
When you click on that request it should display you, whether the request was GET or POST and also what data were sent to this document.
You can also try at comment.php var_dump($_REQUEST); to see what data were sent and how it can be accessed.
By this you can see if server all over receives any data. If yes, then you go for an other server like apache2 for testing purpose to look if bug is fixed.
That's how I would to that, but I suspect that by editing your code for the public, you accidentally withheld some information that would solve this simple problem.
It's very unlikely that web-servers like WAMP had passed the testing environment before publishing a new version allthough no data could be procesed by server
So this never happen to me before until today.
I have a login form trying to send a simple post to the action form. var_dump returns array 0 when i use post method BUT when i use method = get and var_dump the get i get all the strings.
here is my html code
<form name="mlsnavform" id="mlsnavform" action="script/mlsnavform.php" method="POST">
<input id="uname" name="uname"type="text" placeholder="Username" autocomplete="off">
<input id="loginbtn" name="loginbtn" type="submit" value="SIGN IN">
</form>
here is mlsnavform.php
<?php
var_dump($_POST);
?>
And the result of this is array(0) { }
But when i change the method from post to get, and use var_dump($_get) instead of $_post i DO get the values but ofcourse login credentials showing up in your URL address is not something i would ever want to do.
Using get fills my array with what i need tho
array(2) { ["uname"]=> string(9) "damnitphp" ["loginbtn"]=> string(7) "SIGN IN" }
This never happen to me, i've been scrolling on stack for almost 2 days now for a "posible duplicate" before i decide to make a new post but there was only 1 i found which had an answer talking about "PHPStorm" but i do not use phpstorm. I use notepad++(yes i could use sublime or atom or brackets but im so used to notepad i dont feel the need of switching to another text editor).
Anyone know any fix for this? thanks in advance!
EDIT: So today i decide to open a project i made 4months ago that always worked, but the post from that page isnt working either. So what did i do? i decided to to remove that 1 thing i added a couple of weeks ago before all these issues started.
URL REWRITE from IIS so i can remove the .phpextension
So basically this was my issue all along but so far googling around there isnt a single topic on the net where other people are talking about this. If there maybe a similar issue to this. would much appreciated if someone can comment me the link or a solution.thanks in advance.
So my issue is "$_POST" doesnt work when i have my URL Rewrite code in the webconfig. if i remove the rewrite code then the .php extension shows in the browser(which i don't want) but my $_post methods work again.
You can check the enable_post_data_reading in php.ini
From php.ini:
; Whether PHP will read the POST data.
; This option is enabled by default.
; Most likely, you won't want to disable this option globally. It causes $_POST
; and $_FILES to always be empty; the only way you will be able to read the
; POST data will be through the php://input stream wrapper. This can be useful
; to proxy requests or to process the POST data in a memory efficient fashion.
; http://php.net/enable-post-data-reading
Check if this option is uncommented and comment this with ";"
;enable_post_data_reading = Off
You probably are taking the superglobal variable names POST and GET too literal. $_GET is the parsed query string, it's independent of the HTTP method, i.e. it will always be present, even with POST requests. $_POST is the parsed HTTP body when conforming to some constraints (the content-type header has to specify either application/x-www-form-urlencoded or multipart/form-data, and I think the method really has to be "POST" - Note that when NOT conforming to the constraints, even if you'd use the POST method, you won't get any data inside $_POST.
<form name="mlsnavform" id="mlsnavform" enctype="application/x-www-form-urlencoded" action="script/mlsnavform.php" method="POST">
<input id="uname" name="uname"type="text" placeholder="Username" autocomplete="off">
<input id="loginbtn" name="loginbtn" type="submit" value="SIGN IN">
</form>
I can't get the $_POST['name'] values sent from an html form on my php file. I've seen lots of similar questions but nothing helped. I have lot's of includes so I believe it's a scope issue, but I can't figure it out.
index.php
print_r($_POST); //Returns nothing, tried other ways too
//lot's of variables being defined
include 'sql_data_handlers.php';
//instantiating some things
sql_data_handlers.php
//some functions retrieving data from sql db and finally:
include($DOCUMENT_ROOT . "page.html");
page.html
//html stuff
<?php
//Some conditions
include($DOCUMENT_ROOT . "comment_form.html");
?>
comment_form.html
<form action="index.php" name="comment_form" id="comment_form" method="post">
<input type="text" name="name" value="Anonymous" required><br>
//lot's of inputs
<input type="submit">
</form>
I used to have action="send_comment.php" but I realized it could be turned into a function so I ctrl+c and adapted send_comments.php to a function on sql_data_handlers.php. The problem is, now I can't get the $_POST values on index.php to use in the function on sql_data_handlers.php (which is included in index.php).
I would use action="my_php_function_from_data_handlers.php($args)" if it was possible, but I guess it isn't. btw, I already tried action="". This may seem pretty messy but this way I only need one .html for the site layout, pages are on the sql and the .php files do all the job.
Complete source of all files (pretty big, still working on it):
http://pastebin.com/2nRuCpNx
Make sure you don't have any kind of redirects, since you're using index.php to save data, you're probably reloading the page to show the updated comments. And if you're reloading, there'll be no data on $_POST to be printed by print_r().
Try changing the value of the input name attribute to something different from "name". Some configurations have issues with that, especially wordpress.
for example:
<input type="text" name="user_name" value="Anonymous" required>
would you mind to change your
.html filename to .php filename
your codes runs in my local server because sometimes the difference lies in how your web server is configured.
when running in an web server it is best to use .php in your files
I have a php form on my website and it works well under firefox. But whenever I tested on IE(v8 and 9), the form doesn't get sent, and it returns a "IE can't display the webpage" error.
The script is located at http://www.fitnessgrace.com/Vancouver-Personal-Trainers/Vancouver-Personal-Trainers-Contact-Fitness-Grace.htm
Any insights would be very much appreciated.
you are posting the page to http://www.FitnessGrace.com/gdform.php
and you have a hidden input
<input type="hidden" name="redirect" value="../index.html" />
after this point, I can only guess, but I think you are trying to redirect to "../index.html", and since gdform.php is already at the root directory, ../ is meaningless. I think firefox somehow understands that you've made a mistake and doesn't care, but ie doesn't understand.
I have a simple HTML form, sending a post request to a php script. In IE8, the form only works intermittently - most of the time the PHP script sees an empty $_POST variable.
Here's my code:
<html>
<head>
<title>Post test</title>
</head>
<body style="text-align: center;">
<?php
echo "<pre>".print_r($_POST, TRUE)."</pre>";
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="name">
<input type="hidden" name="hidden" value="moo" >
<input type="submit" value="Search" >
</form>
</body>
</html>
Sometimes the print_r gives the response you'd expect (i.e. it's populated with the data from the form), most of the time it's empty.
Not being able to use POST is a bit of a problem for web applications - anyone got any ideas what's going on, and how to fix it?
Thanks everyone for wading in on this one.
It turns out the problem lay in an Apache module I had enabled.
It's a module to allow apache to use Windows authentication to identify a user via their Windows User id - mod_auth_sspi
The effect is caused by a known bug, in the module, but with a simple extra directive this can be worked around, until a fix is added in the next update, as described here:
http://sourceforge.net/projects/mod-auth-sspi/forums/forum/550583/topic/3392037
That sounds very very bizarre. Does it happen in other versions of IE as well?
I can't tell you what the problem is, but here are my suggestions on how to diagnose it:
Print $_REQUEST rather than just $_POST, to see if the data is coming in via another method.
Use a tool like Fiddler or Wireshark to track exactly what is actually being sent by the browser.
Fiddler in particular has been very helpful for me a few times (mainly when debugging Ajax code), and will tell you exactly what was posted by the browser. If your web server is localhost, you can also use Fiddler to track what is received before PHP gets its hands on it. If not, you can use wireshark on the server if you have permissions for installing that sort of thing.
In addition to Fiddler, I would have suggested a browser-based tool like Firebug, but I don't know of one for IE that is good enough (The IE dev toolbar doesn't give you details of request and response data, as far as I know).
I'm suspicious that when the script is telling you that $_POST is empty, you did not actually POST the form. You can check by adding print($_SERVER['REQUEST_METHOD']); after your print_r($_POST);
If you are posting a file some of the time (i.e. with a file input) then make sure you set enctype="multipart/form-data" in your <form> element.
Have you checked the generated html? Is it possible that echo $_SERVER['PHP_SELF'] isn't producing the output you're after, which messes up the form html, which messes up the POST?