adrafa Posted March 21, 2009 Share Posted March 21, 2009 What I need is to retrieve results from a database and use those results as input fields in a form. I was able to do that much but I can't figure out how to echo the results. Here is my code: <?php $result = mysql_query("SELECT * FROM table"); while($row = mysql_fetch_array($result)) { echo $row['sub_class']; echo '<input type="text" name="'.$row['sub_class'].'">'; } ?> This code creates 5 input fields in my form, because the table has 5 rows created. What am I missing to be able to echo each of those 5 input fields? Link to comment https://forums.phpfreaks.com/topic/150511-how-to-assign-query-results-to-input-fields-of-a-form-and-then-echo-them/ Share on other sites More sharing options...
irkevin Posted March 21, 2009 Share Posted March 21, 2009 echo $row['sub_class']; echo '<input type="text" value="'.$row['sub_class'].'">'; it should be the value.. not the name, try it Link to comment https://forums.phpfreaks.com/topic/150511-how-to-assign-query-results-to-input-fields-of-a-form-and-then-echo-them/#findComment-790557 Share on other sites More sharing options...
adrafa Posted March 21, 2009 Author Share Posted March 21, 2009 Thanks for the reply irkevin. What I want to echo is the value entered by the user on those input fields(that each have the name of the sub_class) Link to comment https://forums.phpfreaks.com/topic/150511-how-to-assign-query-results-to-input-fields-of-a-form-and-then-echo-them/#findComment-790560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.