I am using the following PHP code to retrieve the team name from the mysql db table team_details
which contains 2 columns,team_id
and team_name
<?php
mysql_connect("", "", "");
mysql_select_db("db_name");
$data = mysql_query("SELECT team_name FROM team_details");
print "Team A:";
Print "<select name="dropdown">";
while($info = mysql_fetch_array( $data ))
{
Print "<option value='".$info['team_name']."'>".$info['team_name'] . "</option> ";
}
Print '</select>';
?>
Full code
VS
Team B:
<select id="team2" disabled="true">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<button id="sub" disabled="true" name ="choose" onclick="load_players();"> Choose Players</button>
<button type="reset" value="Clear" onclick="reset_load();"> Clear</button>
</form>
</div>
</body>
you error may be here:
Print "<select name="dropdown">";
you need to escpae the double quotes:
Print "<select name=\"dropdown\">";
First of all, you have syntax error here:
Print "<select name="dropdown">";
Escape quotes like this:
Print "<select name='dropdown'>";
Second, use mysql_fetch_assoc instead of mysql_fetch_array, so your code looks like this:
while($info = mysql_fetch_assoc( $data ))
{
Print "<option value='".$info['team_name']."'>".$info['team_name'] . "</option> ";
}
And check your mysql_connect in order to have right values (Host name, user, password)
try following code, replace host, db_username, db_password and db_name
mysql_connect("host", "db_username", "db_password");
mysql_select_db("db_name");
$data = mysql_query("SELECT team_name FROM team_details");
echo "Team A:";
echo "<select name='dropdown'>";
while($info = mysql_fetch_array( $data ))
{
echo "<option value='".$info['team_name']."'>".$info['team_name'] . "</option> ";
}
echo '</select>';