0

I want to insert multiple line in sql as new row. how to do that in php?

In picture I have three text area named text1...text3

I want insert multiple rows in sql database using php

database fields are sl no, FirstNo, SecondNo, ThirdNo

I want to insert at first, first line of all textarea(text1,...text3), then second line(all text areas), then third(all). It will run while finishing last line of all textarea.

How to do?

sacreenshot

Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
SUJOY ROY
  • 45
  • 1
  • 4

1 Answers1

2

First you need to get each line from textarea separately in form of an array for all textareas(you have 3) so there will be three arrays, for that you can check question to get lines separately from textarea .

Once you get the array of separated lines say - $AllLinesArray1 for texarea1, $AllLinesArray2 for texarea2 and $AllLinesArray3 for texarea3, than you can loop through one of it (assuming no. of lines of all textreas is same, array size will be same of all array so the respective key value of each line will be same for every array) insert each line separately like this -

foreach($AllLinesArray1 as $key => $singleLine)

{
    $Line_textarea1 = $AllLinesArray1[$key];
    $Line_textarea2 = $AllLinesArray2[$key];
    $Line_textarea3 = $AllLinesArray3[$key];
    //your MySQL code
    $insert_query = "INSERT INTO tablename( FirstNo , SecondNo, ThirdNo ) VALUES ($Line_textarea1, $Line_textarea2, $Line_textarea3)";
}
Community
  • 1
  • 1
Manoj Salvi
  • 2,639
  • 1
  • 17
  • 21