rickxphp Posted July 23, 2010 Share Posted July 23, 2010 Hi all, I'm trying to display a form based on a dropd own selection. The drop down is propagated from a database query. I have the drop down list displaying, but when I click submit, I can't get the result to display. $sql="SELECT id, company_name FROM webprojects ORDER BY company_name ASC"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $id=$row["id"]; $company_name=$row["company_name"]; $options.="<OPTION VALUE=\"$id\">".$company_name; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP Dynamic Drop Down Menu</title> </head> <body> <form id="form1" name="form1" method="post" action="selected.php"> <SELECT NAME=id> <OPTION VALUE=0>Choose <?=$options.="<OPTION VALUE=\"$id\">".$company_name.'</option>';?> </SELECT> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </form> </body> </html> Any help is greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/208690-displaying-data-from-a-mysql-dropdown-selection/ Share on other sites More sharing options...
fenway Posted July 25, 2010 Share Posted July 25, 2010 I don't see what happens when you click submit -- but that's not a mysql question anymore. Quote Link to comment https://forums.phpfreaks.com/topic/208690-displaying-data-from-a-mysql-dropdown-selection/#findComment-1090928 Share on other sites More sharing options...
rickxphp Posted July 28, 2010 Author Share Posted July 28, 2010 Hi thanks I've done some more work on my scripts. I'm not even sure if this should be posted here now! but here it goes. I have a working dropdown, being populated from mysql. The issue I have is when I try and query to display my choice. query.php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'webform'; mysql_select_db($dbname); @mysql_select_db($dbname) or die( "Unable to select database"); $query="SELECT id,company_name FROM webprojects"; $result = mysql_query ($query); echo "<form name=form method=post action='data.php'> <select company_name=company_name>Company Name"; while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[id]>$nt[company_name]</option>"; } echo "</select>";// Closing of list box echo " <input type=submit value=submit name=button> </form>"; ?> [code] data.php [code] mysql_select_db($dbname); @mysql_select_db($dbname) or die( "Unable to select database"); if(isset($_POST['button'])) { $query = "SELECT 'company_name' FROM webprojects WHERE 'company_name'='" . $_POST['company_name'] ."'"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Company Name</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr><td>"; echo $row['company_name']; echo "</td></tr>"; } echo "</table>"; } else{ } ?> [code] I'm not sure where to go from here Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/208690-displaying-data-from-a-mysql-dropdown-selection/#findComment-1091903 Share on other sites More sharing options...
rickxphp Posted July 28, 2010 Author Share Posted July 28, 2010 Right on Thanks Everybody!!!!!!!!!!! It is passing the id and not the table values. ex company name for for the next query. dropdown is populated from mysql You select a name and click submit script does a query finds that company name in company_name table and displays it. The script will grow from here, but I need to start somewhere. query.php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'webform'; @mysql_select_db($dbname) or die( "Unable to select database"); $query="SELECT id,company_name FROM webprojects"; $result = mysql_query ($query); echo "<form name=form method=post action='data.php'>"; echo "<select name=\"company_name\">"; while($nt=mysql_fetch_assoc($result)){ echo "<option value=$nt[id]>$nt[company_name]</option>"; } echo "</select>";// Closing of list box echo " <input type=submit value=submit name=button> </form>"; ?> data.php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'webform'; mysql_select_db($dbname) or die( "Unable to select database"); $company_name=$_POST['company_name']; if(isset($_POST['button'])) { echo "<tr> <th>Company Name ".$company_name. "</th></tr>"; $query = "SELECT 'company_name' FROM webprojects WHERE 'company_name'='" . $company_name ."'"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Company Name</th></tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr><td>"; echo $row['company_name']; echo "</td></tr>"; } echo "</table>"; } else{ } ?> Quote Link to comment https://forums.phpfreaks.com/topic/208690-displaying-data-from-a-mysql-dropdown-selection/#findComment-1092201 Share on other sites More sharing options...
rickxphp Posted July 28, 2010 Author Share Posted July 28, 2010 ALRIGHTY, Thanks for nothing everybody, I figured it out myself. I have a real sense of accomplishment and an increased feeling that this forum is good for nothing. Quote Link to comment https://forums.phpfreaks.com/topic/208690-displaying-data-from-a-mysql-dropdown-selection/#findComment-1092236 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.