TomFromKWD Posted March 11, 2011 Share Posted March 11, 2011 Guys, quick one. Im writing a script for a form to post info into a MySql table. Now rather than just having a single row for input I'd like to have lets say 10 rows, so I can add 10 records to the database. What I'm pondering is 2 things: 1: can i just repeat <input type="text" name="opponent" size="27" /> over and over, or is it going to need its own name each time for example; <input type="text" name="opponent2" size="27" /> <input type="text" name="opponent3" size="27" /> 2: when it comes to the processing script is it more economical to have the forms input field named the same over and over (if it IS possible) and if not whats the most econimcal way to code my $opp= $_POST['opponent']; $query="INSERT INTO fixtures (match_date, season, opponent) VALUES ('$date', '$season', '$opp',)"; Your help and comments are appreciated as always guys Tom Link to comment https://forums.phpfreaks.com/topic/230318-forms-that-input-data-to-mysql-tables/ Share on other sites More sharing options...
zenag Posted March 11, 2011 Share Posted March 11, 2011 Use type array <input type="text" name="opponent[]" size="27" /> Link to comment https://forums.phpfreaks.com/topic/230318-forms-that-input-data-to-mysql-tables/#findComment-1186096 Share on other sites More sharing options...
TomFromKWD Posted March 11, 2011 Author Share Posted March 11, 2011 Use type array <input type="text" name="opponent[]" size="27" /> Makes sense, but just to clarify, with that, my php script to update the table with form data would still read $opp= $_POST['opponent']; $query="INSERT INTO fixtures (match_date, season, opponent) VALUES ('$date', '$season', '$opp',)"; correct? Link to comment https://forums.phpfreaks.com/topic/230318-forms-that-input-data-to-mysql-tables/#findComment-1186098 Share on other sites More sharing options...
zenag Posted March 11, 2011 Share Posted March 11, 2011 Use "implode" method $opp= implode(',',$_POST['opponent']); Link to comment https://forums.phpfreaks.com/topic/230318-forms-that-input-data-to-mysql-tables/#findComment-1186099 Share on other sites More sharing options...
TomFromKWD Posted March 11, 2011 Author Share Posted March 11, 2011 palm to face right now! Thankyou kindly, just had a brain freeze and couldn't get it right in my head Link to comment https://forums.phpfreaks.com/topic/230318-forms-that-input-data-to-mysql-tables/#findComment-1186102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.