stonebergftw Posted August 11, 2010 Share Posted August 11, 2010 Is there any way to fill a <select> box with entries from a mysql table, and then to have the entries POST to fill in another mysql table. Example. MYSQL table 1 id name 1Tim 2Joe 3Bob Have a drop down select box from table 1, and then fill in the selections in the auto-incrementing table 2, formatted as follows: MYSQL table 2 id name Is this even possible? Quote Link to comment https://forums.phpfreaks.com/topic/210491-filling-a-drop-down-select-box-from-mysql-table/ Share on other sites More sharing options...
fenway Posted August 11, 2010 Share Posted August 11, 2010 Everything's possible -- but this is really two issues: one -- grab all of the values from all of the tables, and two -- deal with php to populate and write out html accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/210491-filling-a-drop-down-select-box-from-mysql-table/#findComment-1098310 Share on other sites More sharing options...
stonebergftw Posted August 12, 2010 Author Share Posted August 12, 2010 Rules noted. Ok, to specifics. Can you explain why this is not working? I think there is something wrong with the following: echo "<option value='<?php echo $donorname;?>'>$donorname</option>"; Out of the following code: <?php $donor=@mysql_query('SELECT id, locationname FROM donors'); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label>Donor: <select name="donor"> <?php while ($donors=mysql_fetch_array($donor)) { $donorname=$donors['locationname']; echo "<option value='<?php echo $donorname;?>'>$donorname</option>"; } ?> </select> <input type="submit" value="SUBMIT"/> </form> There could be something wrong with this code block, but I'm really not sure: <?php $locationname = $_POST['donor']; $donorid = mysql_query("SELECT id FROM donors WHERE locationname='$locationname'"); $sql = "INSERT INTO donations SET donorid='$donorid'"; mysql_query($sql); ?> The select list reads the data just fine, but the INSERT INTO donations SET donorid='$donorid'" is not executing properly. Lets assume that all MYSQL tables are correct and the format of the tables is irrelevant. Any ideas? Help is really really appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/210491-filling-a-drop-down-select-box-from-mysql-table/#findComment-1098326 Share on other sites More sharing options...
fenway Posted August 12, 2010 Share Posted August 12, 2010 Well, check mysql_errror() -- and remove the @ sign before mysql_query(), since that silences errors. What does that echo return? Quote Link to comment https://forums.phpfreaks.com/topic/210491-filling-a-drop-down-select-box-from-mysql-table/#findComment-1098360 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.