473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

tpaine
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
21 20640
ronverdonk
4,258 Expert 4TB
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
steven
143 100+
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
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
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
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
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
steven
143 100+
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
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
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
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
4,258 Expert 4TB
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
steven
143 100+
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
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
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
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
steven
143 100+
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
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
michaelb
534 Expert 512MB
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
rpjd
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
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
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

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

Similar topics

5
by: Winston Kotzan | last post by:
Is there a PHP function that will enable me to find out if a page was called with POST or GET variables? Thanks. -- Winston Kotzan http://www.wakproductions.com/
0
by: Neal | last post by:
Hi All When using a webrequest Post or Get , I keep getting an empty response stream (it is supposed to be an XML file returned via a call to some Systems GetXMLFileAPI) If i paste the URL...
0
by: Ian | last post by:
On the web site: (www.mvps.org/access/) I found a lovely piece of code that retrieves the operating systems name, build number, service pack etc. Is there something similar to retrieve information...
5
by: Roy Gourgi | last post by:
Hi, I am used to working in Visual FoxPro and I would like to be able to create a database and store and retrieve information from it. What is the simplest way to do it and what should I be...
4
by: ElanKathir | last post by:
Hi , What is the different between Post and Get mothed in ASP.Net ? Thanks & Regrads Elankathir, B'lore, India.
4
by: Duffman | last post by:
Hello, I am working with dynamically created WSDL's and I need to change the transaction urls from http to https in the WSDL without redirecting customers to a different location. (I'm using vs...
2
by: James Wong | last post by:
Hi everybody, I would like to know how to retrieve information from AssemblyInfo.vb inside web service. I've tried many different ways including GetExecutingAssembly or similar method but all...
1
by: tromton | last post by:
hello all, ive been wondering latley if someone could change a get variable, so he can change a sql statement that way, that he could delete data from my database. the following ive thought of: ...
22
by: Curious | last post by:
I'm developing a proprietary system in C#.NET. The assembly is in a folder accessible by outside people. Since it's critical that others don't know what it's about and how it's implemented, I...
3
by: mistersulu | last post by:
Hi all: I'm using a wx.ListView object with a multi-threaded wxPython app. The list is dynamically generated and accessed across two or more threads. In spite of the fact that I have checks to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.