Page 1 of 1

PHP: executing urls and variables

Posted: Wed Sep 15, 2004 7:27 am
by CreativeForce
Take a look at this form I could really use some help.

edit patrikG: use

Code: Select all

or

Code: Select all

-tags around code[/color]

This is the form:

<form method="get" name="sw">
<select name="swspecies">
<option value="">Please Select...</option>
<option name="the Ewoks" value="0">the Ewok</option>
<option name="the Wookiee" value="1">the Wookiee</option>
<option name="the Jawa" value="2">the Jawa</option>
<option name="the Mon Calamari" value="3">the Mon Calamari</option>
</select>
<input type"text" name="swcharactername" value="">
<input type="submit" value"Go!">
</form>


This is the PHP:

Code: Select all

$speciewithname_array=array(
0=>"the Ewok",
1=>"the Wookiee",
2=>"the Jawa",
3=>"the Mon Calamarian");
$speciewithoutname_array=array(
0=>"Ewok",
1=>"Wookie",
2=>"Jawa",
3=>"Mon Calamarian");

if(is_array($_post) && count($_post)>1){
if($_post["swcharactername"]!=""){
$speciewithname=$speciewithname_array[$key];}
//what i'm trying to write here is IF swcharactername is NOT blank then I want to extract out your charactername (the name you submitted) and specie for later use. It would maybe be better two makes these two variables into one variable. example: "Creative Force the Ewok". But I don't know how 
elseif($_post["searchtext"]==""){
$speciewithoutname=$speciewithoutname["$key"];}
//what i'm trying to write here is IF swcharactername is blank then charactername is Ewok.
I then want to use the variables i have gathered to open up a window (doesn't matter if it's the same window or a new one):
"http://localhost/starwarsrpgame/characterinfo/($swcharactername + $speciewithname).html or http://localhost/starwarsrpgame/characterinfo/(one variable).html

As you can see from the coding I absolutely know nothing about PHP.

I'm sure you have all written tons of threads explaining this. But I just don't know where to search for them. :(

Thanks

Posted: Wed Sep 15, 2004 7:31 am
by mudkicker
can you color this. i go blinde in few seconds! :(

Posted: Wed Sep 15, 2004 8:49 am
by CoderGoblin
OK Several pointers...
$_POST is used if the form uses a POST method
$_GET is used if the form uses a GET method
$_REQUEST checks both.

All are case sensitive (Your form currently uses GET).

To redirect the page you need the command

Code: Select all

header("Location:nextfile_url?getvals");
  exit;
I would recommend you look up the commands header and urlencode in the php manual.
http://www.php.net/manual/en/