nignix Posted February 23, 2011 Share Posted February 23, 2011 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 https://forums.phpfreaks.com/topic/228584-insert-different-lines-from-to-different-mysql-rows/ Share on other sites More sharing options...
AbraCadaver Posted February 23, 2011 Share Posted February 23, 2011 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"; Link to comment https://forums.phpfreaks.com/topic/228584-insert-different-lines-from-to-different-mysql-rows/#findComment-1178687 Share on other sites More sharing options...
Th3Boss Posted April 1, 2013 Share Posted April 1, 2013 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 https://forums.phpfreaks.com/topic/228584-insert-different-lines-from-to-different-mysql-rows/#findComment-1422226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.