brownd Posted September 17, 2008 Share Posted September 17, 2008 I am trying to have my users store multiple text field values at once, here is a copy of my form code <form name="form1" method="post" action="test2.php"> <table width="100%" border="1"> <tr> <td>Class</td> <td>Title</td> <td>Comments</td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> <tr> <td><label> <input type="text" name="class" id="class" /> </label></td> <td><label> <input type="text" name="book" id="book" /> </label></td> <td><label> <input type="text" name="comments" id="comments" /> </label></td> </tr> </table> <input type="submit" name="submit" id="submit" value="Submit" /> </form> As you can see three fields are repeated multiple times, how do I store these values in mysql and later retreive them. Link to comment https://forums.phpfreaks.com/topic/124667-storing-and-retreiving-multiple-text-fields/ Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Well, first of all, you need unique names for your fields. An easy way would be with a for loop like this: <?php for ($i=0;$i<10;$++){ ?> <tr> <td><label> <input type="text" name="class[<?=$i?>]" id="class<?=$i?>" /> </label></td> <td><label> <input type="text" name="book[<?=$i?>]" id="book<?=$i?>" /> </label></td> <td><label> <input type="text" name="comments[<?=$i?>]" id="comments<?=$i?>" /> </label></td> </tr> <?php } ?> Then your names are in an array of that input field and your ID's are all unique. Link to comment https://forums.phpfreaks.com/topic/124667-storing-and-retreiving-multiple-text-fields/#findComment-643916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.