combo box value not display?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • selvasoft
    New Member
    • Mar 2010
    • 34

    combo box value not display?

    The php script did not retrieve the value from mysql database.
    here i have color field in database.i want show that colors in my combo box
    please find out my attachment.
    if there any errors in following code.
    Code:
    <?php
    $con=mysql_connect("localhost","root","red");
    if(!$con)
    {
       die('Not Connet Our Server'.mysql_error());
    }
    mysql_select_db("my_db",$con);
    $result=mysql_query("select color from gallery");
    echo "<select name='colors'>Shade Color</option>"; 
    while($mycolor=mysql_fetch_array($result))
    {
    echo "<option value=" . $mycolor['id'] .">" . $mycolor['color'] .
    echo "</option>";
    }
    mysql_close($con);
    ?>
    Attached Files
    Last edited by Atli; Mar 12 '10, 01:16 PM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    What is this printing, exactly?

    The only problem I see there is that you left out the "id" field from the SQL query. You need to specify all columns you want it to return, so if you want to use the "id", you need to have the SQL query return that as well.

    Also, you may want to add a "or die(mysql_error ())" after the mysql_query() call, so that you know if the query is failing.

    Comment

    Working...