raduenea Posted March 29, 2022 Share Posted March 29, 2022 I have a strange situation. I want to submit a form with POST method but it's not working. It works only with GET. When I submit with POST nothing show on test.php webpage. How can this be possible ? Can be a server restriction ? HTML: <html> <body> <form action="test.php" method="post"> <input type="text" name="ceva"> <input type="submit" value="go"> </form> </body> </html> PHP: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); if(isset($_POST['ceva'])) { echo $_POST['ceva']; } ?> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/ Share on other sites More sharing options...
gw1500se Posted March 29, 2022 Share Posted March 29, 2022 Looks like $_POST does not contain what you think. Before the 'if' block use this: echo "<pre>"; print_r($_POST); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594680 Share on other sites More sharing options...
ginerjm Posted March 29, 2022 Share Posted March 29, 2022 Is all of the displayed code in a SINGLE script? If so, can you show us THAT script? Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594681 Share on other sites More sharing options...
raduenea Posted March 29, 2022 Author Share Posted March 29, 2022 1 minute ago, ginerjm said: Is all of the displayed code in a SINGLE script? If so, can you show us THAT script? The first script is in html page. The second script is in php page. Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594682 Share on other sites More sharing options...
raduenea Posted March 29, 2022 Author Share Posted March 29, 2022 14 minutes ago, gw1500se said: echo "<pre>"; print_r($_POST); echo "</pre>"; The results with this script is Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594683 Share on other sites More sharing options...
ginerjm Posted March 29, 2022 Share Posted March 29, 2022 Then show us both of those completely Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594684 Share on other sites More sharing options...
gw1500se Posted March 29, 2022 Share Posted March 29, 2022 As you can see $_POST does not contain what you expect. Now you have to figure out why. Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594685 Share on other sites More sharing options...
ginerjm Posted March 29, 2022 Share Posted March 29, 2022 I think there is something we are not being shown that is causing the problem. That's why I would like to see all of the code in each file Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594686 Share on other sites More sharing options...
raduenea Posted March 29, 2022 Author Share Posted March 29, 2022 14 minutes ago, ginerjm said: Then show us both of those completely You can see it in the begining of this post. Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594688 Share on other sites More sharing options...
ginerjm Posted March 29, 2022 Share Posted March 29, 2022 That is ALL OF THE CODE??? Try to run this code as 'test.php'. <?php ini_set('display_errors', 1); error_reporting(E_ALL); echo "now running test.php script<br>"; if(isset($_POST['ceva'])) { echo "Ceva is: ".$_POST['ceva']; } else echo "Ceva is not set<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594689 Share on other sites More sharing options...
ginerjm Posted March 29, 2022 Share Posted March 29, 2022 (edited) Add a name= attribute to your submit button. Let's see what $_POST shows then. Currently the print_r($_POST) is showing you nothing and that can't be. So perhaps you have 2 test.php scripts and you are running the wrong one. Put something into the one you think is being run and let's see if it shows up on your screen. Edited March 29, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594690 Share on other sites More sharing options...
ginerjm Posted March 29, 2022 Share Posted March 29, 2022 Hello? Are you still interested in resolving this or should I go do something else? Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594693 Share on other sites More sharing options...
raduenea Posted March 29, 2022 Author Share Posted March 29, 2022 47 minutes ago, ginerjm said: Hello? Are you still interested in resolving this or should I go do something else? Sorry for delay. It's show: now running test.php script Ceva is not set Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594694 Share on other sites More sharing options...
raduenea Posted March 29, 2022 Author Share Posted March 29, 2022 Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594695 Share on other sites More sharing options...
mac_gyver Posted March 29, 2022 Share Posted March 29, 2022 2 hours ago, raduenea said: The results with this script is these type of problems, where it looks like the code should technically work, are often due to copy/pasting code found on the web, where it has been published and the characters, due to the character encoding being used, aren't actually what they appear to be, or someone typing non-ascii characters as part of the syntax (the base characters for the actual syntax must be straight ascii characters.) what does changing the print_r($_POST) to print_r($_GET) show, i.e. the default form method is get when an unknown value is used for the method attribute? you can also add echo $_SERVER['REQUEST_METHOD']; at that point in the code to see what the browser is submitting the data as. if this shows get data/get method, delete and TYPE the entire method='post' attribute (you may in fact need to delete and re-type the entire <form ...> tag if there are some non-ascii characters in it.) btw - your form and form processing code should be on the same page. this will result in the simplest code and the best User eXperience (UX.) Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594696 Share on other sites More sharing options...
raduenea Posted March 29, 2022 Author Share Posted March 29, 2022 If I switch to GET instead POST, it's working: Results are: now running test.php script Ceva is: gdfgdf Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594697 Share on other sites More sharing options...
mac_gyver Posted March 29, 2022 Share Posted March 29, 2022 3 minutes ago, raduenea said: If I switch to GET instead POST i did NOT state that you should do that. we are trying to determine why a post method form does not work. Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594698 Share on other sites More sharing options...
raduenea Posted March 29, 2022 Author Share Posted March 29, 2022 Interesting. I add in php the line: echo $_SERVER['REQUEST_METHOD'] . '<br>'; In form html I have method='post', and at result it's show GET. now running test.php script GET Ceva is not set Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594699 Share on other sites More sharing options...
ginerjm Posted March 29, 2022 Share Posted March 29, 2022 What you are being told is that the character set being used by the stuff you copied off the internet is wrong. Use that example as a source but TYPE IT IN YOURSELF so that the character set is what you are using. Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594701 Share on other sites More sharing options...
ginerjm Posted March 29, 2022 Share Posted March 29, 2022 And also - when you post code here it is highly recommended that you copy and paste (we know that you know how that's done) it here instead of putting up pictures of it. That way we can more easily view it and if we want to, we can copy it and edit it and place it back if it needs to be done. Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594727 Share on other sites More sharing options...
raduenea Posted March 30, 2022 Author Share Posted March 30, 2022 We develop de code on our local machine witch working fine. Actually the code it's much more complex. But when we put it on the server we identify that no POST was made. So when I create that small piece of code just to test the POST and to write it here. So that small code it's: index.html <html> <body> <form action="test.php" method="post"> <input type="text" name="ceva"> <input type="submit" value="go"> </form> </body> </html> test.php <?php ini_set('display_errors', 1); error_reporting(E_ALL); echo "now running test.php script<br>"; echo $_SERVER['REQUEST_METHOD'] . '<br>'; if(isset($_POST['ceva'])) { echo "Ceva is: ".$_POST['ceva']; } else { echo "Ceva is not set<br>"; } The results: now running test.php scriptGET Ceva is not set Something it's wrong. In html I used post method but the server request GET. Can be server restrictions ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594730 Share on other sites More sharing options...
raduenea Posted March 30, 2022 Author Share Posted March 30, 2022 I modify the html code as below. Replace the submit button to force the post, but no success. The same result, server request is GET. <html> <body> <form method="POST" action="test.php"> <input type="text" name="ceva"> <button type="submit" formmethod="post" formaction="test.php">Submit</button> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594732 Share on other sites More sharing options...
mac_gyver Posted March 30, 2022 Share Posted March 30, 2022 has a post method request ever worked on this server? do you have any .htaccess redirecting or is this server behind a proxy server? Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594733 Share on other sites More sharing options...
ginerjm Posted March 30, 2022 Share Posted March 30, 2022 Let's try something. I am by no means a PHP expert nor do I know anything about installations of it but I see this setting in my phpinfo and I wonder what you have there. In the test.php script add this line: print_r(phpinfo()); Then look at the output in the CORE section. Tell me what the setting is for "enable_post_data_reading". Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594737 Share on other sites More sharing options...
raduenea Posted March 30, 2022 Author Share Posted March 30, 2022 3 hours ago, ginerjm said: Let's try something. I am by no means a PHP expert nor do I know anything about installations of it but I see this setting in my phpinfo and I wonder what you have there. In the test.php script add this line: print_r(phpinfo()); Then look at the output in the CORE section. Tell me what the setting is for "enable_post_data_reading". enable_post_data_reading it's ON for both Local and Master value. Quote Link to comment https://forums.phpfreaks.com/topic/314640-submit-form-with-post/#findComment-1594739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.