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

Link to comment
Share on other sites

  • 2 years later...

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.