By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

combo box value not display?

selvasoft
P: 34
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.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect("localhost","root","red");
  3. if(!$con)
  4. {
  5.    die('Not Connet Our Server'.mysql_error());
  6. }
  7. mysql_select_db("my_db",$con);
  8. $result=mysql_query("select color from gallery");
  9. echo "<select name='colors'>Shade Color</option>"; 
  10. while($mycolor=mysql_fetch_array($result))
  11. {
  12. echo "<option value=" . $mycolor['id'] .">" . $mycolor['color'] .
  13. echo "</option>";
  14. }
  15. mysql_close($con);
  16. ?>
Attached Images
File Type: jpg col.jpg (11.2 KB, 124 views)
Mar 12 '10 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
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.
Mar 12 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.