Jump to content

Inputting data from a textarea.


-Karl-

Recommended Posts

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

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!

 

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?

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'");
		}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.