brax23 Posted August 11, 2008 Share Posted August 11, 2008 I've researched but can't find anything that helps. I'm using the fetch_array function to query a table then build a drop down menu from the results. I have several drop down menus that I'm creating using the same fetch_array statement. I'd like to be able to pass each chosen variable/value from each of the separate drop down menus to the next page. Can someone suggest anything? Here's the code: $members_list = "<select name='name';'>"; $members_list .= "<option selected></option>"; $query_members = "SELECT ProjectNumber,ProjectName FROM projects ORDER BY ProjectNumber"; $result_members = mysql_query($query_members) or die("QUERY MEMBERS FAILED: ".mysql_error()); while ($line = mysql_fetch_array($result_members)) { $itemnumber = $line['ProjectNumber']; $description = $line['ProjectName']; $members_list .= "<option value='$itemnumber'>$itemnumber $description</option>"; } $members_list .= "</select>"; $codes_list = "<select name='code';'>"; $codes_list .= "<option selected></option>"; $query_codes = "SELECT WorkCode, Description FROM workcodes ORDER BY WorkCode"; $result_codes = mysql_query($query_codes) or die("QUERY MEMBERS FAILED: ".mysql_error()); while ($line = mysql_fetch_array($result_codes)) { $codenumber = $line['WorkCode']; $codedescription = $line['Description']; $codes_list .= "<option value='$codenumber'>$codenumber $codedescription</option>"; } $codes_list .= "</select>"; echo "<form method='get' action='Time_3.php'>"; echo "<table border='0' width='50%' cellspacing='0' cellpadding='1'>"; echo " <td><table border='0' width='100%' cellspacing='0'>"; echo " <tr>"; echo " <td width='5%'> </td>"; echo " <tr>"; echo " <td width='5%'> </td>"; echo " <td width='95%'> </td>"; echo " </tr>"; echo " <tr>"; echo " <td colspan='1'><table border='0' width='40%'>"; echo " <tr>"; echo " <td>Project: </td>"; echo " <td>Task Code: </td>"; echo " <td>Time: </td>"; echo " <td>Description: </td>"; echo " <tr></tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time1' size='2'> </td>"; echo " <td><input type='text'name='description1' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time2' size='2'> </td>"; echo " <td><input type='text' name='description2' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time3' size='2'> </td>"; echo " <td> <input type='text' name='description3' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time4' size='2'> </td>"; echo " <td> <input type='text' name='description4' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time5' size='2'> </td>"; echo " <td> <input type='text' name='description5' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time6' size='2'> </td>"; echo " <td> <input type='text' name='description6' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time7' size='2'> </td>"; echo " <td> <input type='text' name='description7' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time8' size='2'> </td>"; echo " <td> <input type='text' name='description8' size='140'></td>"; echo " </table></td>"; echo " </tr>"; echo " </table></td>"; echo " </tr>"; echo "</table>"; echo "<input type='submit' value='Submit' />"; echo "</form>"; Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/ Share on other sites More sharing options...
wildteen88 Posted August 11, 2008 Share Posted August 11, 2008 To get a value from a drop down menu, you use $_POST['your_menu_name'] Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613500 Share on other sites More sharing options...
brax23 Posted August 11, 2008 Author Share Posted August 11, 2008 Thanks wildteen88. You have helped me several times in these forums and I appreciate it. I've tried the $_POST and $_GET form methods on the first page where the menu is created but for some reason either the value is not passing or I'm not asking for it correctly. Here's the code on the next page where I'm simply trying to echo the value: echo $_GET['$members']; echo $_GET[['$codes_list']; Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613600 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Well, that's because you named your select menus 'name' and 'code', respectively. $_GET['name'], $_GET['code']; And also, you have several HTML syntax errors, such as ; after the name attribute. Try validating the page to see what I mean. Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613601 Share on other sites More sharing options...
brax23 Posted August 11, 2008 Author Share Posted August 11, 2008 Thank you DarkWater. I'm actually working in in html and php so my code is: <?PHP mysql_connect(host_name,user_name, pass_word) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); $members_list = "<select name='name';'>"; $members_list .= "<option selected></option>"; $query_members = "SELECT ProjectNumber,ProjectName FROM projects ORDER BY ProjectNumber"; $result_members = mysql_query($query_members) or die("QUERY MEMBERS FAILED: ".mysql_error()); while ($line = mysql_fetch_array($result_members)) { $itemnumber = $line['ProjectNumber']; $description = $line['ProjectName']; $members_list .= "<option value='$itemnumber'>$itemnumber $description</option>"; } $members_list .= "</select>"; $codes_list = "<select name='code';'>"; $codes_list .= "<option selected></option>"; $query_codes = "SELECT WorkCode, Description FROM workcodes ORDER BY WorkCode"; $result_codes = mysql_query($query_codes) or die("QUERY MEMBERS FAILED: ".mysql_error()); while ($line = mysql_fetch_array($result_codes)) { $codenumber = $line['WorkCode']; $codedescription = $line['Description']; $codes_list .= "<option value='$codenumber'>$codenumber $codedescription</option>"; } $codes_list .= "</select>"; echo "<form method='get' action='Time_3.php'>"; echo "<table border='0' width='50%' cellspacing='0' cellpadding='1'>"; echo " <td><table border='0' width='100%' cellspacing='0'>"; echo " <tr>"; echo " <td width='5%'> </td>"; echo " <tr>"; echo " <td width='5%'> </td>"; echo " <td width='95%'> </td>"; echo " </tr>"; echo " <tr>"; echo " <td colspan='1'><table border='0' width='40%'>"; echo " <tr>"; echo " <td>Project: </td>"; echo " <td>Task Code: </td>"; echo " <td>Time: </td>"; echo " <td>Description: </td>"; echo " <tr></tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time1' size='2'> </td>"; echo " <td><input type='text'name='description1' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time2' size='2'> </td>"; echo " <td><input type='text' name='description2' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time3' size='2'> </td>"; echo " <td> <input type='text' name='description3' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time4' size='2'> </td>"; echo " <td> <input type='text' name='description4' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time5' size='2'> </td>"; echo " <td> <input type='text' name='description5' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time6' size='2'> </td>"; echo " <td> <input type='text' name='description6' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time7' size='2'> </td>"; echo " <td> <input type='text' name='description7' size='140'></td>"; echo " </tr>"; echo " <td>$members_list</td>"; echo " <td>$codes_list</td>"; echo " <td><input type='text' name='time8' size='2'> </td>"; echo " <td> <input type='text' name='description8' size='140'></td>"; echo " </table></td>"; echo " </tr>"; echo " </table></td>"; echo " </tr>"; echo "</table>"; echo "<input type='submit' value='Submit' />"; echo "</form>"; ?> I still can't see where I've got any syntax errors on my second page trying to echo with $_GET['name'] or $_GET['code']. Although I did have an error on last post [[ but corrected it. Thanks for your help and patience with a beginner. Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613657 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Here's where you have syntax errors: $members_list = "<select name='name';'>"; It should be: $members_list = "<select name='name'>"; Notice the extra ;' in the original. You did that in a few places I think. That could possible cause some issues. And $_GET['code'] and $_GET['name'] should work. Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613658 Share on other sites More sharing options...
brax23 Posted August 11, 2008 Author Share Posted August 11, 2008 Darn it! Still no go. Can you tell me how to validate please? Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613673 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Validate Or, you can just go to the page you want to validate, then copy and paste this into the address bar and press Enter: javascript:void(window.open('http://validator.w3.org/check?uri='+window.location.href,'','width=800,height=900,status=yes,resizable=yes,scrollbars=yes,location=yes')); Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613688 Share on other sites More sharing options...
brax23 Posted August 11, 2008 Author Share Posted August 11, 2008 Thanks very much DarkWater. Looks like it's working. It's only passing the values from the last menu/row but I think I can fix that by using multiple forms (one for each row of menu's) then name each menu differently. Again, thanks for your help, you sure save people like me a lot of frustration and I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613760 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Thanks very much DarkWater. Looks like it's working. It's only passing the values from the last menu/row but I think I can fix that by using multiple forms (one for each row of menu's) then name each menu differently. Again, thanks for your help, you sure save people like me a lot of frustration and I appreciate it. Or you can try out naming the element with an array name such as name='foo[]', then $_POST['foo'] will be a multi-dimensional array of everything selected. And I'm glad to help. =) Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613771 Share on other sites More sharing options...
brax23 Posted August 11, 2008 Author Share Posted August 11, 2008 I'll try that. I need to learn multi dimensional arrays. One final really newb question. How do I put the [sOLVED] in the post header? Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613785 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Click the button on the bottom left corner of the thread. Quote Link to comment https://forums.phpfreaks.com/topic/119145-paasing-variable-from-drop-down-menu/#findComment-613850 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.