user3362856
user3362856

Reputation: 67

PHP selected item not return selected item from option value selected

I have an HTML form, which returns a list of teams that are held within a database, the list of teams returns fine, however I want to print the selected team on the screen and my code seems to be returning the value 'teams' instead of the actual team being selected. I guess this is something to do with the way the options values re being populated and could use some assistance!

Here is the code:

Team:           
<select name ="team">
<?php for($j =0 ; $j <$rows ; $j++) {
    $row = mysql_fetch_row($result);
?>
   <option value ="teams"><?php echo $row[0];}?></option>
</select>
    <input type="submit" value="Add Player"     />
</form>

<?php 

This is what I am using to echo the team select:

$team       = get_post('team');
echo $team;

Upvotes: 0

Views: 108

Answers (1)

luisnicg
luisnicg

Reputation: 304

<select name ="team">
<?php 
    for($j =0 ; $j <$rows ; $j++) {
        $row = mysql_fetch_row($result);
?>
        <option value ="<?php echo $row[0];?>"><?php echo $row[0];?></option>
<?php
    }
?>
</select>
    <input type="submit" value="Add Player"     />
</form>

$row[0] contains the value that will be sent

Upvotes: 1

Related Questions