Echo into drop down menu

Discussion in 'PHP' started by gilgil2, Mar 6, 2012.

  1. #1
    Hi, I am having some trouble echoing into a drop down menu. Instead of the bandnames that I would like to appear, $band is appearing. Here is my code:


    
    <form action="insert.php" method="post">
    Band Name <select name="band">
    <? $link = mysql_connect(); 
    if (!$link) { 
        die('Could not connect: ' . mysql_error()); 
    } 
    mysql_select_db(); 
    
    
    
    
    
    
        $result = mysql_query("SELECT * FROM bands WHERE Username='$username'");  
     
     
        while($row = mysql_fetch_array($result)) 
        { 
            $band = $row['BandName'] ;
    echo '<option value=\"$band\">$band</option>' ;
        }
    
    
    ?>
    </select>
    
    Code (markup):

    I think it may be something to do with putting . $band . or maybe using '$band' as that is what I have seen but these don't seem to be working for me, so I am either way off or making little mistakes.


    Any help would be greatly appreciated.


    Thanks
     
    gilgil2, Mar 6, 2012 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    You can't call a variable like that in single quotes.

    echo '<option value="'.$band.'">'.$band.'</option>' ;
    PHP:
    Will work
     
    blueparukia, Mar 6, 2012 IP