View Full Version : Inserting multiple rows

05-13-2004, 01:08 PM
Hi all,

I want to get a textarea form and add each new line to a database as a seperate row. Does anyone know how to do this in PHP?

I really haven't a clue where to start :(


05-13-2004, 02:40 PM
You can do that with the explode() (http://www.php.net/explode) function.

$line = explode ("\n", $foo);

Where $foo is the name of your textarea. $line would be an array, then you can handle the array however you want.

foreach($line as $x) {
echo $x;

That would echo out each line. Or you can do your insert from there.

05-13-2004, 03:43 PM
You would get ur textarea text by:

$textarea_text = $_POST['textarea_name'];

Then as mobeilebadboy suggested, but could do:

foreach($line as $x) {
$sql="INSERT INTO table (text) VALUES ('$x')";
$outcome = mysql_query($sql);

05-13-2004, 11:41 PM
I'll try it out later, thanks guys :) Thought it would be more complicated then that.