View Full Version : Inserting multiple rows
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 :(
Thanks,
Mike
mobilebadboy
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.
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);
}
I'll try it out later, thanks guys :) Thought it would be more complicated then that.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.