-Karl- Posted April 18, 2010 Share Posted April 18, 2010 I have a textarea, with so many rows and columns, but that's not important. Each line will have a different name, example: username1 username2 etc What I need to do is create a script which will create a database record, per line. So maybe exploding it? I'm not too sure, then use for each to insert each line in to a seperate record. If you need me to explain further, please don't hesitate to ask. Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/ Share on other sites More sharing options...
PC Nerd Posted April 18, 2010 Share Posted April 18, 2010 Hi, You might want to try looking at exploding on the new line, so using "\r\n" or something. i'm not sure if its 100% what you're looking for but it should work. If you're entering smaller amounts of data like that it might make sense to have a "add new field" button and jsut have a table of text fields. if you name them: username[1], username[2] etc, then you will be able to access them in php using an array and thus use the same code as you would resulting from the explode(). Good luck! Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/#findComment-1044159 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 Basically, it's a memberlist, for clans. So each username needs to be on a seperate line, then it will be exploded and inserted seperately into the database. Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/#findComment-1044191 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 Okay so I have: <?php if (!isset($_POST['addmembers'])){ ?> <div id="tab4"> <form action="settings.php" method="post"> <textarea name="addmembers" rows="20" columns="30"></textarea> <div style=" margin-left:20px; margin-top:20px; margin-bottom:20px;"> <input type="submit" name="submit" value="submit"> </form> </div> </div> <?php } else { $explode1 = $_POST['addmembers']; $explodeadd = explode("\r\n", $explode1); echo $explodeadd[0]; echo $explodeadd[1]; } ?> echo $explodeadd[0]; works perfectly and echos the first in the array. However, the array I'm going to allow could have up to 100 different ones (which I'd also like to limit to a maximum of 100). What would be the best way to go about doing a for each, to input the data in to the database? Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/#findComment-1044201 Share on other sites More sharing options...
SaMike Posted April 18, 2010 Share Posted April 18, 2010 foreach($explodeadd as $key => $index){ //You do nothing with key, its just the line number (0 being the first line) //Now this loops trough every username and $index should be it. echo $index; } Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/#findComment-1044212 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 Perfect thanks. Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/#findComment-1044219 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 Mmm, wondering why this won't work: foreach($explodeadd as $key => $index){ //You do nothing with key, its just the line number (0 being the first line) //Now this loops trough every username and $index should be it. $url = $arr['url']; $addthem = mysql_query("INSERT INTO `members` (username,clanurl) VALUES ('$index','$url'"); } Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/#findComment-1044226 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 Any ideas anyone? Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/#findComment-1044247 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 Really need help with this =\ Link to comment https://forums.phpfreaks.com/topic/198921-inputting-data-from-a-textarea/#findComment-1044292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.