Jump to content

insert different lines from <textarea> to different mysql rows


nignix

Recommended Posts

Hello, is it possible to insert somehow information from textarea to mysql?

For example i have 3 lines in text area:

John Tacker is a bad guy

Tom Tacker has a big nose

Ted Tacker is the same person as John Tacker

and i want to insert them in table's different rows

One way:

 

$lines = array_map('mysql_real_escape_string', explode("\n", $_POST['textarea']));
$values = "VALUES ('" . implode("'), ('", $lines) . "')";

$query = "INSERT INTO table_name (column_name) $values";

  • 2 years later...
  On 2/23/2011 at 4:10 PM, AbraCadaver said:

 

One way:

 

$lines = array_map('mysql_real_escape_string', explode("\n", $_POST['textarea']));
$values = "VALUES ('" . implode("'), ('", $lines) . "')";

$query = "INSERT INTO table_name (column_name) $values";

 

 

This doesnt work. I have tried it so many different ways.

 

I have a textarea that has data like

Info1

Info2

Info3

Info4

Info5

 

I have a table that has an auto increment ID and a Name column and I want each line from the textarea in its own row inserted in the Name column.

I tried like posted above and so many other ways. Here is my last attempt.

 

$lines = array_map('mysql_real_escape_string', explode("\n", $_POST['TextArea']));

$values = implode("'), ('", $lines);

 

$query = "INSERT INTO Table (`ID`,`Name`) VALUES (NULL, '$values')";

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.