IF / ELSE IF with drop down menus

First off hello! Secondly I am trying to get a drop down box to choose it’s default value using an if / elseif statement. This code comes from a alter player page so the information is being pulled from the SQL. Every time I run the script it always outputs male as the default. If someone could shed some light on why this is not working for me or point me in a better direction that would be greatly appreciated.

[php]
$query=“SELECT * FROM player WHERE id = $id”;
$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error());
while($row = mysql_fetch_array($result)){

/** Variables */
$firstname= $row[‘firstname’];
$lastname= $row[‘lastname’];
$sex= $row[‘sex’];

if ($sex = “Male”)
echo "Sex:  MaleFemale  ";
elseif ($sex = “Female”)
echo "Sex:  FemaleMale  ";
}[/php]

Hello and welcome!

I think you have typo in your if() statement. Instead of comparing two strings you’re assigning the “Male” value to your $sex variable :slight_smile:

correct:
[php]if ($sex == "“Male”)[/php]

Make that: [php]if ($sex == “Male”)[/php]…

and same thing for the female.

Figures it was something so simple… thanks for your help. :-[

Sponsor our Newsletter | Privacy Policy | Terms of Service