Stupid Question

So why does this display ALL of the echo’s instead of only the one that is correct with what ?rank= is.

[php]<?php

$rank = $_GET[‘rank’];

if ($rank == Airman+Basic) { echo "Airman Basic Image
"; }
if ($rank == Airman) { echo "Airman Image
"; }
if ($rank == afc) { echo "Airman First Class Image
"; }
if ($rank == Senior+Airman) { echo "Senior Airman Image
"; }
if ($rank == Staff+Sergeant) { echo "Staff Sergeant Image
"; }
if ($rank == Technical+Sergeant) { echo "Technical Sergeant Image
"; }
if ($rank == Master+Sergeant) { echo "Master Sergeant Image
"; }
if ($rank == First+Sergeant) { echo "First Sergeant Image
"; }
if ($rank == Chief+Master+Sergeant) { echo "Chief Master Image
"; }
if ($rank == First+Sergeant) { echo "First Sergeant Image
"; }
if ($rank == Command+Chief+Master+Sergeant) { echo "Command Chief Master Sergeant Image
"; }
if ($rank == Chief+Master+Sergeant+of+the+Air+Force) { echo "Chief Master Sergeant of the Air Force Image
"; }
if ($rank == Second+Lieutenant) { echo "Second Lieutenant Image
"; }
if ($rank == First+Lieutenant) { echo "First Lieutenant Image
"; }
if ($rank == Captain) { echo "Captain Image
"; }
if ($rank == Major) { echo "Major Image
"; }
if ($rank == Lieutenant+Colonel) { echo "Lieutenant Colonel Image
"; }
if ($rank == Colonel) { echo "Colonel Image
"; }
if ($rank == Brigadier+General) { echo "Brigadier General Image
"; }
if ($rank == Major+General) { echo "Major General Image
"; }
if ($rank == Lieutenant+General) { echo "Lietenant General Image
"; }
if ($rank == General) { echo "General Image
"; }
if ($rank == General+of+the+Air+Force) { echo "General of the Air Force Image
"; }
else {
echo “Something has gone wrong”;
}

?>[/php]

Stupid Reply ::slight_smile:

Missing quotes? “Airman+Basic” ect per if statement

Austin,

Can rank only be one of the those? If so, you should use a “switch / case” statement instead of the all the if’s, the way it is now, if rank is any thing other then, General+of+the+Air+Force, the you will always the “Something has gone wrong” printed, because the ELSE is only on that one if statement.

Mike

Added quotes and now it displays nothing.

Yes it can only be one of those, there is a form on the previous page with drop down selection.

Can you post your original form? That would help to see what it’s doing.

Sure, there is a form before that one for each military branch, and then the next page looks like this, only with one of these with each branch and it’s ranks. Which works fine, so I’m not sure what’s going on.

[php]<?php

if ($_GET[‘branch’] == AirForce)
echo "

Select Your Rank

<select name='rank' id='rank'>
  <option selected>Airman Basic</option>
  <option>Airman</option>
  <option value=afc>Airman First Class</option>
  <option>Senior Airman</option>
  <option>Staff Sergeant</option>
  <option>Technical Sergeant</option>
  <option>Master Sergeant</option>
  <option>First Sergeant</option>
  <option>Chief Master Sergeant</option>
  <option>First Sergeant</option>
  <option>Command Chief Master Sergeant</option>
  <option>Chief Master Sergeant of the Air Force</option>
  <option>Second Lieutenant</option>
  <option>First Lieutenant</option>
  <option>Captain</option>
  <option>Major</option>
  <option>Lieutenant Colonel</option>
  <option>Colonel</option>
  <option>Brigadier General</option>
  <option>Major General</option>
  <option>Lieutenant General</option>
  <option>General</option>
  <option>General of the Air Force</option>
</select>

"; ?>[/php]

You should change the form’s action to post, rather than a get. Then use this switch statement:

[php]
$rank = $_POST[‘rank’];
switch ($rank){
case ‘Airman Basic’:
echo "Airman Basic Image
";
break;
case ‘Airman’:
echo "Airman Image
";
break;
case ‘afc’:
echo "afc Image
";
break;
case ‘Senior Airman’:
echo "Senior Airman Image
";
break;
case ‘Staff Sergeant’:
echo "Staff Sergeant Image
";
break;
case ‘Technical Sergeant’:
echo "Technical Sergeant Image
";
break;
default:
echo “Something has gone wrong”;
break;
}
[/php]
You will have to add the rest of the case statements there. Notice, you don’t need the + signs in the string.

The problem was it’s not value of options

You must do :

Airman Basic
Airman

Got that going. Now I need to know how to make this work, the backgrounds are selectable via radio buttons and come in as just the filename, so how would I get this to work getting the spaces out from around $background?

[php]$im = ImageCreateFromPng(“backgrounds/ $background .png”);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service