mattichu Posted December 13, 2011 Share Posted December 13, 2011 hi, I'm sruggling to get a drop down list to post the chosen value from an sql database.. could someone please point me in the right direction many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/253115-drop-down-list-from-sql-then-post/ Share on other sites More sharing options...
Shenzi1985 Posted December 14, 2011 Share Posted December 14, 2011 im having this issue as well i got the list working and submitting just cant get it to post another result that i need Quote Link to comment https://forums.phpfreaks.com/topic/253115-drop-down-list-from-sql-then-post/#findComment-1297774 Share on other sites More sharing options...
Nodral Posted December 14, 2011 Share Posted December 14, 2011 What code do you have at the moment? Are you getting any errors? Are you just wanting someone to write this for you, and if so you may want to post in the frelancing section. Quote Link to comment https://forums.phpfreaks.com/topic/253115-drop-down-list-from-sql-then-post/#findComment-1297780 Share on other sites More sharing options...
mattichu Posted December 14, 2011 Author Share Posted December 14, 2011 Here is the code ive tried but it doesnt post anything <?php $username="*****"; $password="*****"; $database="checkmyw_database"; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT $staffno FROM rotastaff WHERE wkbeg='$wkbeg'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $staffname=mysql_result($result,$a,"staff1"); $username="******"; $password="******"; $database="checkmyw_database"; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query2="SELECT id FROM rotastaff WHERE wkbeg='$wkbeg'"; $result2=mysql_query($query2); $num2=mysql_numrows($result2); mysql_close(); $id=mysql_result($result2,$a,"id"); ?> <div style="position:absolute; top:370px; left:400px;"> <font color="white" size="3"> <table width="300px"> <td> Select New Name: </td> </table> </font> </div> <div style="position:absolute; top:430px; left:400px;"> <font color="white" size="3"> <table width="300px"> <td> <a href="/new/usernotlisted.php">User Not Listed?</a> </td> </table> </font> </div> <?php mysql_connect("localhost","******","*****"); mysql_select_db("checkmyw_database") or die("Unable to select database"); $result = mysql_query("select DISTINCT username from members"); ?> <form action="/new/newrotastaffprocess.php" method="post"> <div style="position:absolute; top:400px; left:400px;"> <? echo '<select name="user"><OPTION>'; echo "Select a User</OPTION>"; echo "Create New..</OPTION>"; while ($row = mysql_fetch_array($result)){ $username = $row["username"]; echo "<OPTION value=\"$username\">$username</OPTION>"; } echo '</SELECT>'; ?> </div> <div style="position:absolute; top:397px; left:550px;"> <input type="hidden" size="20" value="<?php echo $result;?>" name="username"> <input type="hidden" size="20" value="<?php echo $wkbeg;?>" name="wkbeg"> <input type="hidden" size="20" value="<?php echo $staffno;?>" name="staffno"> <input type="submit" size="5" value="Change"> </div> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253115-drop-down-list-from-sql-then-post/#findComment-1297917 Share on other sites More sharing options...
Nodral Posted December 19, 2011 Share Posted December 19, 2011 Hi This line <input type="hidden" size="20" value="<?php echo $result;?>" name="username"> , will not post anything as $result is a mysql data result. What code do you have in /new/newrotastaffprocess.php? How do you know it's not posting anything? Quote Link to comment https://forums.phpfreaks.com/topic/253115-drop-down-list-from-sql-then-post/#findComment-1299284 Share on other sites More sharing options...
Ivan Ivković Posted December 19, 2011 Share Posted December 19, 2011 // Form fetching if(isset($_POST['option'])){ $selected_option = $_POST['option']; // Your selected option successfully posted. Now do anything with it. } // Options listout with onselect - post option <?php mysql_connect("localhost","******","*****"); mysql_select_db("checkmyw_database") or die("Unable to select database"); $result = mysql_query("SELECT DISTINCT user_id username FROM members"); // USER ID MUST BE FETCHED AND SELECTED ?> <form action="/new/newrotastaffprocess.php" method="post"> <div style="position:absolute; top:400px; left:400px;"> <?php echo '<select name=\'user\' onchange=\'this.form.submit()\'><option selected>Select a User</option>'; // onchange=\'this.form.submit()\' is what submits the form. echo 'Create New...</option>'; while ($row = mysql_fetch_array($result)){ $username = $row["username"]; echo "<OPTION value=\"$_POST['user_id']\">{$_POST['username']}</OPTION>"; } echo '</select>'; ?> </div> </form> // YOU DIDN'T CLOSE THIS One more thing, I suggest you start using mysqli function for database. And more of these ''. "" check for variables, '' check only for text so it's faster. Quote Link to comment https://forums.phpfreaks.com/topic/253115-drop-down-list-from-sql-then-post/#findComment-1299301 Share on other sites More sharing options...
Ivan Ivković Posted December 19, 2011 Share Posted December 19, 2011 CORRECTION (unable to modify, don't know why) I missed a character. :S $result = mysql_query("SELECT DISTINCT user_id, username FROM members"); // USER ID MUST BE FETCHED AND SELECTED One more thing, I suggest you start using mysqli function for database. And more of these ''. "" check for variables, '' check only for text so it's faster. Quote Link to comment https://forums.phpfreaks.com/topic/253115-drop-down-list-from-sql-then-post/#findComment-1299304 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.