Passing data and variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
doodlebee
Forum Newbie
Posts: 2
Joined: Tue Sep 10, 2002 6:01 pm

Passing data and variables

Post by doodlebee »

I'm fairly new to PHP - I did a search for my problem, but couldn't seem to find the answer. Perhaps if I ask outright, I can find out what I'm doing wrong, eh?

I'm trying to create a form using HTML. This form will have a drop-down list of all 50 states. When the user selects a state, the state selected will be processed by my PHP script, and the information for that state will be displayed. It's working, as far as selecting the state and going through the PHP - however, it's displaying the information for all 50 states, not just the one selected. I'll show you my code - shortened to 2 states instead of all 50 (because that would just be silly to show you all 50, right?)

My HTML page is called "Licensing.html" and looks as such (sans all the body tags and stuff - I'm just getting to the meat of it):

<form action="processform.php?action=$state" method="GET">
<select name="state[]" width="25">
<option value="#"><b>Select a State</b></option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<input name="action" type="submit" value="Submit"></form>

Processform.php reads as such (again, sans body tags and such):

<?php

$state = $HTTP_GET_VARS['state'];

if ($state !="AL") {
print "Alabama informational page stuff here, set out in a nice tables. I left out all the actual formatting of what text will be displayed, just because it's quite a bit of stuff.";
}

if ($state !="AK") {
print "Ditto here - lots of stuff I left out to make this a little shorter.";
}

?>

Am I oversimplifying or am I (hopefully - because I *was* thinking I was getting good at figuring out this PHP thing!) on the right track? Thanks so much.
dusty
Forum Contributor
Posts: 122
Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA

Post by dusty »

Code: Select all

&lt;?
if(isset($_POST&#1111;action])) {
  if($_POST&#1111;state] == "AL") {
    echo "Info on Alabama";
  }
  if($_POST&#1111;state] == "AK") {
    echo "Info on Alaska";
  }
}
?&gt;

&lt;form action="&lt;?=$PHPSELF?&gt;" method="POST"&gt;
&lt;select name="state" width="25"&gt;
&lt;option&gt;&lt;b&gt;Select a State&lt;/b&gt;&lt;/option&gt;
&lt;option value="AL"&gt;Alabama&lt;/option&gt;
&lt;option value="AK"&gt;Alaska&lt;/option&gt;
&lt;input name="action" type="submit" value="Submit"&gt;&lt;/form&gt;
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Code: Select all

<form action="processform.php?action=$state" method="GET"> 
<select name="state" width="25"> 
<option value="#"><b>Select a State</b></option> 
<option value="AL">Alabama</option> 
<option value="AK">Alaska</option> 
<input name="action" type="submit" value="Submit"></form>
doodlebee
Forum Newbie
Posts: 2
Joined: Tue Sep 10, 2002 6:01 pm

Thanks!

Post by doodlebee »

Thank you *so* much. You have reduced the injuries to my forehead by an unbelievable amount - it's working like a charm now. Thanks so much!
Post Reply