HTTP_POST_VARS...

This is a discussion on "HTTP_POST_VARS..." within the PHP Forum section. This forum, and the thread "HTTP_POST_VARS... are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old Nov 6th, 2003, 16:27
Junior Member
Join Date: Oct 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
HTTP_POST_VARS...

Hi there ppl,

Just starting out with PHP4 and require a little assistance with register_globals = Off. The 2 php pages work fine with the register_globals = On, but I must be using the HTTP_POST_VARS incorrectly or something.

states.php is as follows:
<?php
$StatesOfTheUSA = array (1 => "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming");
for ($counter=1; $counter<51; $counter++) {
echo"<OPTION>$StatesOfTheUSA[$counter]</OPTION>";
}
echo "</SELECT>

";
for ($counter=1; $counter<51; $counter++) {
echo"<INPUT TYPE=HIDDEN NAME='HiddenState[]' VALUE='$StatesOfTheUSA[$counter]'>";
}
echo "<INPUT TYPE=SUBMIT></FORM>";
?>

capitals.php is as follows:
<?php
$StateCapital = array (0 => "Montgomery", "Juneau", "Phoenix", "Little Rock", "Sacramento","Denver","Hartford", "Dover","Tallahasse", "Atlanta", "Honolulu", "Boise", "Springfield","Indianapolis", "Des Moines", "Topeka", "Frankfort", "Baton Rouge","Augusta","Annapolis","Boston", "Lansing", "Saint Paul","Jackson", "Jefferson City", "Helena","Lincoln", "Carson City","Concord", "Trenton","Santa Fe", "Albany", "Raleigh","Bismarck","Columbus","Oklahoma City", "Salem", "Harrisburg", "Providence", "Columbia","Pierre", "Nashville", "Austin","Salt Lake City", "Montpelier","Richmond","Olympia","Charleston" , "Madison","Cheyenne");
for ($counter=0; $counter<50; $counter++)
{
if($HiddenState[$counter]==$State)
{
echo"The State capital is $StateCapital[$counter]";
}
}
?>


These work fine with register_globals = On , so could somebody show me how to use the HTTP_POST_VARS correctly in this scenario?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Nov 6th, 2003, 17:26
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
All I can say is this is the strangest piece of code i've ever seen and way more complicated than it needs to be... Here's my take:

states.php
Code: Select all
<FORM ACTION="capitals.php" METHOD=POST>
What state do you want to know the capital of?
<SELECT NAME=State>

<?php
$StatesOfTheUSA = array (0 => "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming");
for ($counter=0; $counter<50; $counter++) {
	echo"<OPTION VALUE='$counter'>$StatesOfTheUSA[$counter]</OPTION>"; 
}
echo "</SELECT>

";
echo "<INPUT TYPE=SUBMIT></FORM>";
?>
capitals.php
Code: Select all
<?php
// Get your POST vars
$State = $HTTP_POST_VARS[State];
$HiddenState = $HTTP_POST_VARS[HiddenState];

$StateCapital = array (0 => "Montgomery", "Juneau", "Phoenix", "Little Rock", "Sacramento","Denver","Hartford", "Dover","Tallahasse", "Atlanta", "Honolulu", "Boise", "Springfield","Indianapolis", "Des Moines", "Topeka", "Frankfort", "Baton Rouge","Augusta","Annapolis","Boston", "Lansing", "Saint Paul","Jackson", "Jefferson City", "Helena","Lincoln", "Carson City","Concord", "Trenton","Santa Fe", "Albany", "Raleigh","Bismarck","Columbus","Oklahoma City", "Salem", "Harrisburg", "Providence", "Columbia","Pierre", "Nashville", "Austin","Salt Lake City", "Montpelier","Richmond","Olympia","Charleston", "Madison","Cheyenne");
for ($counter=0; $counter<50; $counter++) {
	if($counter==$State) {
	echo"The State capital is $StateCapital[$counter]";
	exit;
	}
}
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Nov 6th, 2003, 17:27
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Please note:
$HiddenState = $HTTP_POST_VARS[HiddenState];
is completly useless... it isn't used, I changed the code after I put that in and forgot to take it out.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
http_post_vars

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:10.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42