$_GET works but $_POST doesn't
Moderator: General Moderators
$_GET works but $_POST doesn't
So, I've been trying to write a memory test program, with images (thus, C is out of the question, for cross-platform issues). I've come across an interesting problem. To prevent users from crashing the system, I resorted to $_POST. However, upon testing, I noticed that print_r($_POST) shows nothing, while the same code (except for method="post" => method="get") runs perfectly, and data is transmitted properly when the form uses get. Any idea on what's going on? The outputs for print_r($_POST) and print_r($_GET) are as follows:
Using POST:
Array ( [id] => 1 )
Array ( )
Using GET:
Array ( [id] => 1 [qn] => 20 [ans] => Array ( [2] => W [4] => images/ser.GIF ) )
Array ( )
GET shows what I want if I were using post, but it's not happening. Any ideas, guys?
Using POST:
Array ( [id] => 1 )
Array ( )
Using GET:
Array ( [id] => 1 [qn] => 20 [ans] => Array ( [2] => W [4] => images/ser.GIF ) )
Array ( )
GET shows what I want if I were using post, but it's not happening. Any ideas, guys?
Re: $_GET works but $_POST doesn't
in $_GET u can get the information from the address
$_POST need a method = "post" and an action ..
$_POST need a method = "post" and an action ..
Re: $_GET works but $_POST doesn't
I'm not a novice at PHP. What I'm saying is that get transmits the information, but post doesn't. I have no clue what in the world is going on. And the very reason why this bugs me is because I don't want all the get variables to show up in the URL, not to mention a character limit on get transmission
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: $_GET works but $_POST doesn't
Could you show us the html for the form which submits the $_GET/$_POST data?
Re: $_GET works but $_POST doesn't
Sure. But it's PHP generated, and...the form is enormous in size (2/3 of the HTML code):
<form action="../test?" method="get">
<input type="hidden" value="2" name="id" /><font style="font-weight:bold;">Question number 1<input type="hidden" readonly="readonly" name="qn" value="1" size="1" />:</font><br />
<table cellspacing="0" cellpadding="0" style="border:0;">
<tr>
<td style="text-align:left;"><a href="../test?id=1" class="normalText"><input type="button" value="Previous question" /></a></td>
<td style="text-align:right;"><input type="submit" value="Save and go to next question" /></td>
</tr>
</table>
<font style="font-family:Times New Roman;"><br />
Given an amino acid with
name Alanine, 3-letter abbreviation Ala, structural formula <img src="../images/ala_s.GIF" style="vertical-align:top" />
<br /><br />
Choose the correct properties for this amino acid.<br />
<table style="border:5px;background:#440000;">
<tr><td style="border:5px;text-align:right;vertical-align:center;padding:5px;">1-Letter Abbreviation</td><td style="border:5px;text-align:left;vertical-align:center;padding:5px;">
<table cellspacing="0" cellpadding="0" style="border:0;">
<tr>
<td style="text-align:left;"><a href="../test?id=1" class="normalText"><input type="button" value="Previous question" /></a></td>
<td style="text-align:right;"><input type="submit" value="Save and go to next question" /></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" style="border:0;background:#440000;">
<tr><td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/0" value="Y" /></td>
<td><label style="vertical-align:top" for="2/0"><font style="vertical-align:top">Y</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/1" value="A" /></td>
<td><label style="vertical-align:top" for="2/1"><font style="vertical-align:top">A</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/2" value="Q" /></td>
<td><label style="vertical-align:top" for="2/2"><font style="vertical-align:top">Q</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/3" value="C" /></td>
<td><label style="vertical-align:top" for="2/3"><font style="vertical-align:top">C</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/4" value="K" /></td>
<td><label style="vertical-align:top" for="2/4"><font style="vertical-align:top">K</font></label></td>
</tr>
<tr>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/5" value="W" /></td>
<td><label style="vertical-align:top" for="2/5"><font style="vertical-align:top">W</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/6" value="T" /></td>
<td><label style="vertical-align:top" for="2/6"><font style="vertical-align:top">T</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/7" value="H" /></td>
<td><label style="vertical-align:top" for="2/7"><font style="vertical-align:top">H</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/8" value="P" /></td>
<td><label style="vertical-align:top" for="2/8"><font style="vertical-align:top">P</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/9" value="E" /></td>
<td><label style="vertical-align:top" for="2/9"><font style="vertical-align:top">E</font></label></td>
</tr>
<tr>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/10" value="D" /></td>
<td><label style="vertical-align:top" for="2/10"><font style="vertical-align:top">D</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/11" value="L" /></td>
<td><label style="vertical-align:top" for="2/11"><font style="vertical-align:top">L</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/12" value="F" /></td>
<td><label style="vertical-align:top" for="2/12"><font style="vertical-align:top">F</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/13" value="S" /></td>
<td><label style="vertical-align:top" for="2/13"><font style="vertical-align:top">S</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/14" value="I" /></td>
<td><label style="vertical-align:top" for="2/14"><font style="vertical-align:top">I</font></label></td>
</tr>
<tr>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/15" value="V" /></td>
<td><label style="vertical-align:top" for="2/15"><font style="vertical-align:top">V</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/16" value="M" /></td>
<td><label style="vertical-align:top" for="2/16"><font style="vertical-align:top">M</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/17" value="N" /></td>
<td><label style="vertical-align:top" for="2/17"><font style="vertical-align:top">N</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/18" value="R" /></td>
<td><label style="vertical-align:top" for="2/18"><font style="vertical-align:top">R</font></label></td>
<td style="vertical-align:center;text-align:center;"><input type="radio" name="ans[2]" id="2/19" value="G" /></td>
<td><label style="vertical-align:top" for="2/19"><font style="vertical-align:top">G</font></label></td>
</tr></table>
<table cellspacing="0" cellpadding="0" style="border:0;">
<tr>
<td style="text-align:left;"><a href="../test?id=1" class="normalText"><input type="button" value="Previous question" /></a></td>
<td style="text-align:right;"><input type="submit" value="Save and go to next question" /></td>
</tr>
</table>
</td></tr>
<tr><td style="border:5px;text-align:right;vertical-align:center;padding:5px;">Ball-and-Stick Model</td><td style="border:5px;text-align:left;vertical-align:center;padding:5px;">
<table cellspacing="0" cellpadding="0" style="border:0;">
<tr>
<td style="text-align:left;"><a href="../test?id=1" class="normalText"><input type="button" value="Previous question" /></a></td>
<td style="text-align:right;"><input type="submit" value="Save and go to next question" /></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" style="border:0;background:#440000;">
<tr><td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/0"><img src="../images/ala.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/0" value="images/ala.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/1"><img src="../images/asn.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/1" value="images/asn.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/2"><img src="../images/asp.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/2" value="images/asp.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/3"><img src="../images/pro.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/3" value="images/pro.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/4"><img src="../images/met.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/4" value="images/met.GIF" /></td>
</tr>
<tr>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/5"><img src="../images/glu.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/5" value="images/glu.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/6"><img src="../images/phe.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/6" value="images/phe.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/7"><img src="../images/cys.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/7" value="images/cys.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/8"><img src="../images/gly.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/8" value="images/gly.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/9"><img src="../images/thr.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/9" value="images/thr.GIF" /></td>
</tr>
<tr>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/10"><img src="../images/arg.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/10" value="images/arg.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/11"><img src="../images/lys.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/11" value="images/lys.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/12"><img src="../images/leu.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/12" value="images/leu.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/13"><img src="../images/val.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/13" value="images/val.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/14"><img src="../images/ser.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/14" value="images/ser.GIF" /></td>
</tr>
<tr>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/15"><img src="../images/ile.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/15" value="images/ile.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/16"><img src="../images/his.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/16" value="images/his.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/17"><img src="../images/trp.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/17" value="images/trp.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/18"><img src="../images/gln.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/18" value="images/gln.GIF" /></td>
<td style="vertical-align:center;text-align:center;"><label style="vertical-align:top" for="4/19"><img src="../images/tyr.GIF" style="vertical-align:top" /></label><br />
<input type="radio" name="ans[4]" id="4/19" value="images/tyr.GIF" /></td>
</tr></table>
<table cellspacing="0" cellpadding="0" style="border:0;">
<tr>
<td style="text-align:left;"><a href="../test?id=1" class="normalText"><input type="button" value="Previous question" /></a></td>
<td style="text-align:right;"><input type="submit" value="Save and go to next question" /></td>
</tr>
</table>
</td></tr>
</table>
<table cellspacing="0" cellpadding="0" style="border:0;">
<tr>
<td style="text-align:left;"><a href="../test?id=1" class="normalText"><input type="button" value="Previous question" /></a></td>
<td style="text-align:right;"><input type="submit" value="Save and go to next question" /></td>
</tr>
</table>
</font>
</form>
Re: $_GET works but $_POST doesn't
are you sure that it is correct while you use the "post" method ?wqian94 wrote:<form action="../test?"....
Re: $_GET works but $_POST doesn't
More than certain. The only switch I have to make to change from GET to POST is method="get" to method="post"
Re: $_GET works but $_POST doesn't
Ok... I didn't know that you can use the "?" at the end of your URL if you are using the POST method... I had the impression that the "?" at the end (plus the variables/parameters) is added automatically to your URL when you use the GET method...
Re: $_GET works but $_POST doesn't
You can only use $_POST if the <form action="post">
However the reverse is not true for $_GET. You can use $_GET no matter what the form action is. The only difference is that if you're using action=GET your form variables will be appended to the URL.
However the reverse is not true for $_GET. You can use $_GET no matter what the form action is. The only difference is that if you're using action=GET your form variables will be appended to the URL.
Re: $_GET works but $_POST doesn't
You are absolutely correct. However, since ? indicates a sequence of GET variables, test.php? simply means that test.php has no GET variables passed to itI had the impression that the "?" at the end (plus the variables/parameters) is added automatically to your URL when you use the GET method...
Re: $_GET works but $_POST doesn't
Interesting... you always learn something new 
I did test your form... and works perfect for me with POST or GET
output with POST
Array ( [id] => 2 [qn] => 1 [ans] => Array ( [2] => T [4] => images/gly.GIF ) )
I did test your form... and works perfect for me with POST or GET
output with POST
Array ( [id] => 2 [qn] => 1 [ans] => Array ( [2] => T [4] => images/gly.GIF ) )
Re: $_GET works but $_POST doesn't
Okay then...that's really weird. I guess the question should be changed to "why does my php server screw up?"
I have a feeling that apache is behind all this.
Thanks
I have a feeling that apache is behind all this.
Thanks
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: $_GET works but $_POST doesn't
I doubt that this is anything to do with the web server. HTML forms and POST go back a long way, and - quite simply - they work!
It is, I guess, worth checking that nothing happens to the $_POST array between the point where the form sends it and the point where you read it eg some action which unsets various of the $_POST variables. When you ask the script to print the $_POST array, is that the very first thing your script does, or do other things happen first?
It is, I guess, worth checking that nothing happens to the $_POST array between the point where the form sends it and the point where you read it eg some action which unsets various of the $_POST variables. When you ask the script to print the $_POST array, is that the very first thing your script does, or do other things happen first?
Re: $_GET works but $_POST doesn't
it's the first line of my php
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: $_GET works but $_POST doesn't
You mean the first line in "test?" - the script to which the form data is sent?
I guess that "test" is not the proper name of the script - it will be test.php or test.html - try putting in the proper path of the script to which you are sending the data, and lose the final "?", which isn't needed and may conceivably be creating problems.
Like mikosiko, I have loaded your script onto my local machine and I have found that it sends the get/post data perfectly.
I guess that "test" is not the proper name of the script - it will be test.php or test.html - try putting in the proper path of the script to which you are sending the data, and lose the final "?", which isn't needed and may conceivably be creating problems.
Like mikosiko, I have loaded your script onto my local machine and I have found that it sends the get/post data perfectly.