By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

PHP is unable to retrieve information via $_POST on my localhost but $_GET works?

tpaine
P: 9
Let me preface this by saying that this is most certainly not a code issue but a config issue. I have been able to implement the code fine on my live server, this problem only occurs on my localhost. I have 7 years experience with various web langauges so we can skip the "METHOD='POST'" comments.

I recently setup PHP and Apache (and mySQL) on my windows XP box. This is my first experience with PHP and it took me a long time to get everything working so bear with me. Everything was fine until I attempted to grab something using $_POST["mypostvar"] which returned an error saying "mypostvar" was not found while $_GET["mygetvar"] works fine.
The exact error is : "Notice: Undefined index: mypostvar".
I tried running var_dump($_POST);die; and it also returned nothing. I've tried all sorts of changes within php.ini including:
register_globals = "on"
gpc_order = "GPC"
I also tried the following things:
$_REQUEST["process"]
$HTTP_RAW_POST_DATA with always_populate_raw_post_data on

I have scoured the internet looking for a solution and so far the only thing I found was a solution that I have to pay for over on Experts-Exchange . I would really not have to pay $10 for the answer but I find developing via FTP to be unacceptable.

Version Info:
PHP Version 5.2.0RC6-dev
Apache Version:Apache/2.2.3 (Win32) PHP/5.2.0RC6-d
Nov 30 '06 #1
Share this Question
Share on Google+
21 Replies


ronverdonk
Expert 2.5K+
P: 4,258
I am sorry, but I don't have a clue. The only thing I could think of was the variables_order and the post_max_size parameters in php.ini.

What is the effect of omitting E,C and S like you do? Not that I can think of a logical explanation, but just to be sure I'd try the default variables_order='EGPCS'. You haven't accidentally set the post_max_size to 0, have you? No I don't think so. But still, give it a try.

Sorry I can't help you here really, but I've tried.

Ronald :cool:
Nov 30 '06 #2

100+
P: 143
It seems a little strange how you can find the GET variable, but not the POST. If the data is being sent via POST it should not show up in GET.

On the page in question, can you place this code after the POST has been submitted. It should print an array of all the input.

Expand|Select|Wrap|Line Numbers
  1. echo "<pre>".print_r($_REQUEST, 1)."</pre>";
Dec 1 '06 #3

tpaine
P: 9
I am sorry, but I don't have a clue. The only thing I could think of was the variables_order and the post_max_size parameters in php.ini.

What is the effect of omitting E,C and S like you do? Not that I can think of a logical explanation, but just to be sure I'd try the default variables_order='EGPCS'. You haven't accidentally set the post_max_size to 0, have you? No I don't think so. But still, give it a try.

Sorry I can't help you here really, but I've tried.

Ronald :cool:
Thanks for the tips Ronald but I'm still stuck :-\

I have "post_max_size = 8M" by default and I tried variables_order = "EGPCS" with no success.

I'm so ideologically opposed to paying for information like this but it's to the point where I've wasted far more money in time spent on this issue. I will have to resort to Experts-Exchange if I don't get any more tips in the next day. When I do find the answer I will be sure to post it back here.
Dec 1 '06 #4

tpaine
P: 9
It seems a little strange how you can find the GET variable, but not the POST. If the data is being sent via POST it should not show up in GET.

On the page in question, can you place this code after the POST has been submitted. It should print an array of all the input.

Expand|Select|Wrap|Line Numbers
  1. echo "<pre>".print_r($_REQUEST, 1)."</pre>";
My original post was a little confusing, but it's not that information that should be in the POST is showing up in the GET. What I meant to say is that information passed in the query string is retrievable while information passed in a post is not.
Dec 1 '06 #5

P: 19
URL=https://secure.experts-exchange.com/register.jsp?query=php+_post+empty&clearTAFilter=t rue&srid=zjn%2BshtK13RDZyry87R6HA%3D%3D&redirectUR L=%2Fsearch.jsp%3Fquery%3Dphp%2B_post%2Bempty%26se archType%3Dall%26Submit.x%3D0%26Submit.y%3D0&rsid= 10]Experts-Exchange[/url] . I would really not have to pay $10 for the answer but I find developing via FTP to be unacceptable
An easy way around Experts-Exhange (at least existing answers) is when you have found the answer through Google to click on "Cached". It'll show the answers plain as day. :-)

Sean
Dec 1 '06 #6

tpaine
P: 9
An easy way around Experts-Exhange (at least existing answers) is when you have found the answer through Google to click on "Cached". It'll show the answers plain as day. :-)

Sean
Perhaps you have a better method than I but i believe EE places their "pay for" answers in spot blocked in their robots.txt so spiders (ie: search engines) can't find/cache it. This is what I get when I attempt to use Google Cache
Dec 1 '06 #7

100+
P: 143
Did you try printing the $_REQUEST array as I suggested? It should show everything passed in via cookies, post and get. See if anything shows up after your post send. It will at least determine if the data is even reaching php.
Dec 2 '06 #8

tpaine
P: 9
Did you try printing the $_REQUEST array as I suggested? It should show everything passed in via cookies, post and get. See if anything shows up after your post send. It will at least determine if the data is even reaching php.
oh sorry, yes I had already tried _REQUEST as well ... no luck
Dec 2 '06 #9

P: 19
Perhaps you have a better method than I but i believe EE places their "pay for" answers in spot blocked in their robots.txt so spiders (ie: search engines) can't find/cache it. This is what I get when I attempt to use Google Cache
Hmm. Works for me. Here's what I do:
  1. Do a search on Google
  2. Find an EE link
  3. Click on "Cached" (down below) instead of the result link
Anyhow, do you have code we could look at? Not to insult your posts, but I haven't seen any code yet.

Thanks!
Sean
Dec 4 '06 #10

tpaine
P: 9
Hmm. Works for me. Here's what I do:
  1. Do a search on Google
  2. Find an EE link
  3. Click on "Cached" (down below) instead of the result link
Anyhow, do you have code we could look at? Not to insult your posts, but I haven't seen any code yet.

Thanks!
Sean
Yes some EE links are cached by google but not all. If you could find a cached version of the page I need I would be deeply in your debt.
As for my code it's incredibly simple:
Expand|Select|Wrap|Line Numbers
  1. <?
  2. print "_REQUEST['process']:" . $_REQUEST['process'] . "<br>";
  3. ?>
  4.  
And the form looks like this:
Expand|Select|Wrap|Line Numbers
  1.   <form action="ecard.php" name="frm" method="POST" onSubmit="return validateForm(this);">
  2.     <input type="hidden" name="process" value="free">
  3.     <input type="hidden" name="postcardHTML" value="">
  4.     Recipient's Email Address:<br><input type="text" size="40" name="emailTo"><br>
  5.     Sender's Email Address:<br><input type="text" size="40" name="emailFrom"><br>
  6.     Email Subject:<br><input type="text" size="40" name="subject"><br>
  7.     Message:<br><textarea name="message" rows="10" cols="40"></textarea><br>
  8.     <input type="button" value="preview" onClick="showPreview()">&nbsp;&nbsp;&nbsp;<input type="submit" value="send">
  9.   </form>
  10.  
Dec 5 '06 #11

ronverdonk
Expert 2.5K+
P: 4,258
I am totally confused about this. I copied your code, made a JS function to do a validate and ran it (only thing I did not include was the preview routine). And without errors it shows up in the $_POST of the called script!

So I wonder, is there something in the JS validateForm that can cause this? I am no JS expert, but at least we could try to exclude all possible errors.

If you take the onsubmit validation call out of the form, does it work then?

Ronald :cool:
Dec 5 '06 #12

100+
P: 143
Ok, I see you're trying to access request directly - don't bother. Try printing the entire REQUEST array just to see what it contains when you run your code.

I would try stripping down your form of all javascript calls, to see if they're the root of the problem. In fact, I just did it for you. I ran the form and I printed everything fine:

Expand|Select|Wrap|Line Numbers
  1. <form action="index.php" method="post" >
  2.     <input type="hidden" name="process" value="free" />
  3.     <input type="hidden" name="postcardHTML" value="" />
  4.     Recipient's Email Address:<br><input type="text" size="40" name="emailTo" /><br>
  5.     Sender's Email Address:<br><input type="text" size="40" name="emailFrom" /><br>
  6.     Email Subject:<br><input type="text" size="40" name="subject" /><br>
  7.     Message:<br><textarea name="message" rows="10" cols="40" ></textarea><br>
  8.     <input type="submit" value="send" />
  9.   </form>
  10.  
Then ran this:

Expand|Select|Wrap|Line Numbers
  1. echo "<pre>".print_r($_REQUEST, 1)."</pre>";
  2.  
And the output:

Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [process] => free
  4.     [postcardHTML] => 
  5.     [emailTo] => asxas
  6.     [emailFrom] => xasxax
  7.     [subject] => asxasxas
  8.     [message] => xasxasx
  9. )
  10.  
Look at your javascript for debugging.

[edit]
Heh, I see I was beaten to the punchline. =]
Dec 5 '06 #13

tpaine
P: 9
I tried running the same submit with zero javascript and with the generic _REQUEST with the same results. It does not surprise me that ronverdonk was able to run the code just fine because I do not think this is a code issue, rather it is a configuration issue with either apache or php.
Dec 5 '06 #14

P: 19
I tried running the same submit with zero javascript and with the generic _REQUEST with the same results. It does not surprise me that ronverdonk was able to run the code just fine because I do not think this is a code issue, rather it is a configuration issue with either apache or php.
And if you run it with $_POST? Using $_POST is more secure anyway, since it is a direct reference to the posted items and does not allow you to accept $_GET variables.

Sean
Dec 5 '06 #15

tpaine
P: 9
And if you run it with $_POST? Using $_POST is more secure anyway, since it is a direct reference to the posted items and does not allow you to accept $_GET variables.

Sean
Yes, I have tried _POST as well and everything else under the sun... again, this is not a code issue
Dec 6 '06 #16

100+
P: 143
Ok, in that case - HOW did you go about installing apache and PHP on your machine? Did you download and install the components individually? Did you use a pre-packaged, pre-setup installer that contains both apache and php? Have you tried removing the php/apache install and re-installing it, either using the same method you used before, or another method? Have you looked at the apache config, or just the php config?
Dec 6 '06 #17

tpaine
P: 9
Ok, in that case - HOW did you go about installing apache and PHP on your machine? Did you download and install the components individually? Did you use a pre-packaged, pre-setup installer that contains both apache and php? Have you tried removing the php/apache install and re-installing it, either using the same method you used before, or another method? Have you looked at the apache config, or just the php config?
I downloaded and installed each individual component which took me quite some time as it was the first time I had done so. For this reason I am quite reluctant to start from scratch. If you can recommend a good "pre-packaged" number I would greatly appreciate it.

Incidentally I found a friend with a paid EE account and they retrieved the solution to the issue which doesn't help me in the slightest.
Hi! All,

Thank you so much for all your replies. The problem was with the my Plesk control Panel "View Site" issue. I could figure out and it's fine now.

Regards,
S:
Dec 7 '06 #18

Expert 100+
P: 534
I am puzzled too... but I wonder if you could check all configuration files, including the top-level .htaccess file for something like this:

< Limit POST >
Order deny,allow
Deny from all
< /Limit >
Dec 7 '06 #19

P: 25
I am puzzled too... but I wonder if you could check all configuration files, including the top-level .htaccess file for something like this:

< Limit POST >
Order deny,allow
Deny from all
< /Limit >
I am submitting data from a php webpage form to a database using a php script executed by an xmlhttprequest. The problem I am having is that I am submitting thie data via the URL with GET, but I am not getting anything from $_GET['variable-name'] in my php script. As far as I can tell, my php script looks fine, I can figure out why the data is not getting through. Can someone spot the problem?

this is my php webpage
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <? include("http://localhost/Project/customers.php") ?>
  3. <HTML>
  4.  <HEAD>
  5.   <TITLE> ALLIED AUTO PARTS </TITLE>
  6.   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  7.   <META NAME="Generator" CONTENT="EditPlus">
  8.   <META NAME="Author" CONTENT="">
  9.   <META NAME="Keywords" CONTENT="">
  10. <script type="text/javascript" language="javascript">
  11. var poststr = "?";
  12. function addCustomer()
  13.     { 
  14.     var url="http://localhost/Project/addCustomer.php";
  15.     if(window.XMLHttpRequest)
  16.     http = new XMLHttpRequest(); 
  17.     else if (window.ActiveXObject)
  18.     http  = new ActiveXObject(Microsoft.XMLHTTP); 
  19.     http.onreadystatechange = function()
  20.         { 
  21.  
  22.         if(http.readyState == 4)
  23.             {
  24.  
  25.             if(http.status == 200)
  26.                 {
  27.                 alert(http.responseText);
  28.                 }    
  29.             else    
  30.                 {
  31.                 alert("no customer added");
  32.                 }    
  33.             } 
  34.         }
  35.         http.open("GET", url + poststr, true); 
  36.         http.setRequestHeader("text"); 
  37.         http.send(null); 
  38.     }
  39.  
  40. function deleteCustomer()
  41.     { 
  42.     var url="http://localhost/Project/deleteCustomer.php";
  43.     if(window.XMLHttpRequest)
  44.     http = new XMLHttpRequest(); 
  45.     else if (window.ActiveXObject)
  46.     http  = new ActiveXObject(Microsoft.XMLHTTP); 
  47.     http.onreadystatechange = function()
  48.         { 
  49.         alert(http.readyState);
  50.         if(http.readyState == 4)
  51.             {
  52.             alert(http.status)
  53.             if(http.status == 200)
  54.                 {
  55.                 alert(http.responseText);
  56.                 }    
  57.             else    
  58.                 {
  59.                 alert("no customer deleted");
  60.                 }    
  61.             } 
  62.         }
  63.         http.open("GET", url + poststr, true); 
  64.         http.setRequestHeader("text"); 
  65.         http.send(null); 
  66.     }
  67.  
  68. function reset()
  69.     {
  70.         document.updateCustomer.customer_name.value = "";
  71.         document.updateCustomer.customer_address.value = "";
  72.         document.updateCustomer.customer_contact_no.value = "";
  73.     }
  74.  
  75. function add(obj)
  76.     {
  77.     if((document.updateCustomer.customer_name.value == "") || (document.updateCustomer.customer_address.value == "") || (document.updateCustomer.customer_contact_no.value == ""))
  78.         {
  79.         alert("One or more fields are missing");
  80.         }
  81.     else
  82.         {
  83.         alert("ok");
  84.         poststr += "document.updateCustomer.customer_name.value" + "&document.updateCustomer.customer_address.value" + "&document.updateCustomer.customer_address.value";
  85.         addCustomer();
  86.         }
  87.     }
  88.  
  89. function del(obj)
  90.     {
  91.     if((document.updateCustomer.customer_name.value == "") || (document.updateCustomer.customer_address.value == "") || (document.updateCustomer.customer_contact_no.value == ""))
  92.         {
  93.         alert("One or more fields are missing");
  94.         }
  95.     else
  96.         {
  97.         alert("ok");
  98.         poststr += "document.updateCustomer.customer_name.value" + "&document.updateCustomer.customer_address.value" + "&document.updateCustomer.customer_address.value";
  99.         deleteCustomer();
  100.         }
  101.     }
  102. </script>
  103.  
  104.   </HEAD>
  105.     <BODY onload="reset();">
  106. <p align="center">
  107. To add a new customer fill in the new customers name, address and contact number, then click <b>addCustomer</b>.
  108. <p align="center">
  109. To delete an existing customer, fill in the the details form the customers listed above, then click <b>deleteCustomer</b>.
  110. <p>
  111. <table border="1" align="center">
  112. <tr>
  113. <td align="center">Customer Name</td>
  114. <td><input type="hidden" size="10"/></td>
  115. <td align="center">Customer Address</td>
  116. <td><input type="hidden" size="10"/></td>
  117. <td align="center">Customer Contact Number</td>
  118. </tr>
  119. <tr>
  120. <form name="updateCustomer" method="GET" action="$_SERVER['PHP_SELF']">
  121. <td align="center"><input type="text" name="customer_name" id="customer_name" size="25" value=""/></td>
  122. <td><input type="hidden" size="10"/></td>
  123. <td align="center"><input type="text" name="customer_address" id="customer_address" size="25" value=""/></td>
  124. <td><input type="hidden" size="10"/></td>
  125. <td align="center"><input type="text" name="customer_contact_no" id="customer_contact_no" size="12" value=""/></td>
  126. <td><input type="hidden" size="10"/></td>
  127. <td align="center"><input type="button" name="addCustomer" value="addCustomer" onclick="add(this);"/></td>
  128. <td><input type="hidden" size="10"/></td>
  129. <td align="center"><input type="button" name="deleteCustomer" value="deleteCustomer" onclick="del(this);"/></td>
  130. </form>
  131. </tr>
  132. </table>
  133. </p>
  134. <H1 align="center">ALLIED AUTO PARTS</H1>
  135. <p>
  136. <TABLE align="center">
  137. <TR>
  138.     <TD align="center" colspan="6"><H3>Choose from the following funtions</H3></TD>
  139. </TR>
  140. <TR>
  141.     <TD><a href="ViewParts.php">View Parts</a></TD>
  142.     <TD><a href="Purchases.php">Purchases</a></TD>
  143.     <TD><a href="Sales.php">Sales</a></TD>
  144.     <TD><a href="UpdateParts.php">Add parts</a></TD>
  145.     <TD><a href="UpdateCustomer.php">Update Customer</a></TD>
  146.     <TD><a href="UpdateSupplier.php">Update Supplier</a></TD>
  147. </TR>
  148. </TABLE>
  149. </body>
  150.  
and this is my php script
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $connect=pg_connect("dbname=DatabaseName host=localhost user=User password=password");
  3. if (!pg_connection_busy($connect))
  4.     {
  5.     $customer_name = $_GET["customer_name"];
  6.     $customer_address = $_GET["customer_address"];
  7.     $customer_contact_no = $_GET["customer_contact_no"];
  8.     echo "1 . $customer_contact_no . 2 . $customer_address . 3 . $customer_contact_no";
  9.     $result=pg_query($connect, "insert into customer values('$customer_name', '$customer_address', '$customer_contact_no')");
  10.     echo "New customer added";
  11.     }
  12. ?>
  13.  
Apr 29 '07 #20

P: 1
I had the same issue with localhost but 127.0.0.1 worked.

When I tried to use 127.0.0.1/test.html the $_POST worked.
When I tried to use localhost/test.html the $_POST would not work.


But when I entered just 127.0.0.1 I received a request for a login. After fixing this issue the original issue with localhost not passing $POST was fixed. Here is what steps I took which seemed to fix the issue.

Within the IIS application I went to Directory Security and confirmed the anonynomous login was enabled. I then went to Internet Explorer and open Internet Options /Security/ Local Internet / Sites / Advance/ and added http://127.0.0.1

I closed Internet Explorer and restarted IIS.

Every thing started working.

Hope this helps.
Guy
May 19 '07 #21

P: 1
i have just managed to solve this problem that i was facing. this could be unrelated to the specific problem here, but it may help others.

i had a site which was running SSL .. i had a mod rewrite in an .htaccess file that forced everything over SSL.

i was posting to the non SSL url, which meant that the post data was not getting through to the PHP.

spent nearly a day going over this, and it was one little "s" that was missing.
Jan 29 '12 #22

Post your reply

Sign in to post your reply or Sign up for a free account.