rvinikof Posted July 20, 2007 Share Posted July 20, 2007 I have a loop that creates the option to enter more than one book, author ect., where $q is just the number they enter that determines how many times the text boxes show up. for($i=0; $i < $q; $i++) { echo '<b>Book author:</b> <input type = "text" name = "bookauthor"/>'; echo '<b>Book title:</b> <input type = "text" name = "booktitle"/>'; echo '<b>Book edition:</b> <input type = "text" name = "edition"/>'; echo '<b>ISBN:</b> <input type = "text" name = "isbn"/>'; echo '<b>Required or Optional?</b> <select name = "reqoropt">'; echo '<option value = "required">Required</option><option value = "optional">Optional</option></select>'; } How do I then update this into my table? Before this is updated, I will have a requestID and a courseID that is inserted $q times. I want to have each author, title, ect. be inserted into a different requestID. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 20, 2007 Share Posted July 20, 2007 Add "[]" to field names so data is posted in array <?php for($i=0; $i < $q; $i++) { echo 'Book author: <input type = "text" name = "bookauthor[]"/>'; echo 'Book title: <input type = "text" name = "booktitle[]"/>'; echo 'Book edition: <input type = "text" name = "edition[]"/>'; echo 'ISBN: <input type = "text" name = "isbn[]"/>'; echo 'Required or Optional? <select name = "reqoropt[]">'; echo '<option value = "required">Required</option><option value = "optional">Optional</option></select>'; } ?> to process <?php foreach ($_POST['bookauthor'] as $k => $bookauthor) { $booktitle = $_POST['booktitle'][$k]; $edition = $_POST['edition'][$k]; $isbn = $_POST['isbn'][$k]; $reqoropt = $_POST['reqoropt'][$k]; $sql = "INSERT INTO tablename (bookauthor,booktitle,edition,isbn,reqoropt) VALUES ('$bookauthor','$booktitle','$edition','$isbn','$reqoropt')"; } ?> Quote Link to comment 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.