burge124 Posted February 27, 2008 Share Posted February 27, 2008 hi, im using this tutorial could you just check that it works ok? the page loads fine but the dropdown menu never takes information from the database ive tried playing about with it but no luck! http://www.phpsimple.net/tutorials/dynamic_dropdown_menu/ thanks Quote Link to comment Share on other sites More sharing options...
drisate Posted February 27, 2008 Share Posted February 27, 2008 can you n least post your code so we can compare Quote Link to comment Share on other sites More sharing options...
drisate Posted February 27, 2008 Share Posted February 27, 2008 I know this is a long shot but did you enter you connection info in mysql_connect("localhost","",""); Quote Link to comment Share on other sites More sharing options...
burge124 Posted February 27, 2008 Author Share Posted February 27, 2008 hi, here is my modified code from the online tutorial, this connects to the table "chapter" and within that table are ChapterID (pk) and ChapterTitle. Any help would be great! <? // Connect database mysql_connect("localhost","root",""); mysql_select_db("questiondb"); // If submitted, check the value of "select". If its not blank value, get the value and put it into $select. if(isset($select)&&$select!=""){ $select=$_GET['select']; } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> "> Car company : <select name="select"> <option value="">--- Select ---</option> <? // Get records from database (table "chapter"). $list=mysql_query("SELECT * FROM chapter ORDER BY ChapterID asc"); // Show records by while loop. while($row_list=mysql_fetch_assoc($list)){ ?> <option value="<? echo $row_list['ChapterID']; ?>" <? if($row_list['ChapterID']==$select){ echo "selected"; } ?>><? echo $row_list['ChapterTitle']; ?></option> <? // End while loop. } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <hr> <p> <? // If you have selected from list box. if(isset($select)&&$select!=""){ // Get records from database (table "chapter"). $result=mysql_query("SELECT * FROM chapter WHERE ChapterID='$select'"); $row=mysql_fetch_assoc($result); ?> Information about <strong><? echo $row['ChapterTitle']; ?></strong> company...</p> <p>........................................<br> ........................................<br> ........................................ <? // End if statement. } // Close database connection. mysql_close(); ?> </p> </body> </html> Quote Link to comment Share on other sites More sharing options...
burge124 Posted February 27, 2008 Author Share Posted February 27, 2008 hi, im still stuck on this, any suggestions? Quote Link to comment Share on other sites More sharing options...
kts Posted February 27, 2008 Share Posted February 27, 2008 I know this is a long shot but did you enter you connection info in mysql_connect("localhost","",""); Quote Link to comment Share on other sites More sharing options...
burge124 Posted February 27, 2008 Author Share Posted February 27, 2008 yeah mysql_connect("localhost","root",""); Quote Link to comment Share on other sites More sharing options...
revraz Posted February 27, 2008 Share Posted February 27, 2008 Two things to try. First, use mysql_error() after your query to make sure it's valid. Second, use print_r ($row_list) and see if your array is populating. Quote Link to comment Share on other sites More sharing options...
burge124 Posted February 27, 2008 Author Share Posted February 27, 2008 query's are valid but $row_list isnt populating anything Quote Link to comment Share on other sites More sharing options...
revraz Posted February 27, 2008 Share Posted February 27, 2008 I would change the <? tags to <?php as well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.