deepdiver30 Posted December 11, 2007 Share Posted December 11, 2007 I have a PHP Form with a list box. The list box contains value queried from a mySQL database and the control on the form is generated programatically within PHP and echo'd to the screen, which works fine, however I am having trouble trying to find out from the PHP code what the user has selected. I want to be able to record the user's selection in a variable so that i can then perform another query based on the initial selection. Some places I have read, I need to use JavaScript to do this, other places think that I can do this within HTML and somehow echo the results from the query into the HTML via PHP - I'm confused ??? I hope this makes sense, but let me know if you need any clarification, code examples etc. DeepDiver30 Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 You might want to post some code. Quote Link to comment Share on other sites More sharing options...
deepdiver30 Posted December 11, 2007 Author Share Posted December 11, 2007 Code as suggested - this is dev only at the moment <?php //Setup Connection to Database $user="root"; $host="localhost"; $password="password"; $database="DiggersDirect"; $connection = mysql_connect($host,$user,$password) or die ("Could Not Connect"); $db = mysql_select_db ($database,$connection) or die ("Could Not Select"); //Build and Run the Query $query = "SELECT DISTINCT description FROM machines ORDER BY DESCRIPTION"; $result = mysql_query($query) or die ("Could not execute Query"); //Display HTML Select Box echo "<select name='description'>\n"; //Loop to get everything while ($row = mysql_fetch_array($result)) { extract($row); echo "<option value='$description'>$description\n"; } echo "</select>\n"; ?> 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.