Darkmatter5 Posted April 24, 2008 Share Posted April 24, 2008 I have a text box, a list that's generated by a query and a submit button. I know how to submit the data entered from the text box into the table, but now do I reference the data selected from the list. Here's the insert code I use. <?php if(isset($_POST['addsurvey'])) { include 'library/dbconfig.php'; include 'library/opendb.php'; $Survey=$_POST['Survey']; $SurvCounty=$_POST['SurvCounty']; //put new type data from form into the types table $insertdata="INSERT INTO byrnjobdb.surveys (Survey, SurvCounty) VALUES ('$Survey', '$SurvCounty')"; mysql_query($insertdata) or die('Error, insert query failed'); //after new survey data is applied to surveys table, display success message echo "New Survey ADDED..."; include 'library/closedb.php'; } else {} ?> And here's the code I have to construct the list. <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query=mysql_query(sprintf("SELECT County FROM byrnjobdb.counties ORDER BY County ASC")); echo "<select name='SurvCounty'>"; while ($result=mysql_fetch_assoc($query)) { $r=$result['County']; echo "<option value='$r'>$r</option>"; } echo "</select>"; include 'library/closedb.php'; ?> any ideas? Link to comment https://forums.phpfreaks.com/topic/102768-insert-data-from-list/ Share on other sites More sharing options...
Barand Posted April 24, 2008 Share Posted April 24, 2008 Apart from a couple of redundancies (sprintf() and the "else {}") it looks OK are you getting any errors? Link to comment https://forums.phpfreaks.com/topic/102768-insert-data-from-list/#findComment-526458 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.