从sql获取数据到下拉列表(在html中选择\选项)

I am trying to build a drop down element in html, and to add the values according to user pre-choice. Lets say I have table with one col is game type ans second is a name field. So if the user first drop down choice is basketball - so another drop down list is opened with all the basketball fields as options.

so I have my html file which has inside this php lines:

$game_type = $_POST['gameType'];

$con = mysql_connect("localhost", "root", "Jbtraining1");
if (!$con)
    die('Could not connect: ' . mysql_error());

$db_selected = mysql_select_db("test_sport",$con);
$sql = ("SELECT * FROM fields WHERE game_type = '$game_type'");
$result = mysql_query($sql,$con);

while($row = mysql_fetch_array($result))
    echo "<option value='".$row['field_name_en']."'>" . $row['field_name_en'] . "</option>";
?>
</select>

but this lines does not work. I think most of the lines work well cause if i chage this line:

$game_type = $_POST['gameType'];

to let say to this line -

$game_type = "basketball";

It does work just fine.

Thanks

Change your file extension from .html to .php

Hope this helps

Use

  echo $_POST['gameType']; 

to see if the variable is send.

It sounds like it isn't send because you say it works when you use:

 $game_type = "basketball";

If the echo is empty something gos wrong when you send the variable.

If that is the case post the code you use to post the variable.