MySQL insert from a textarea to multiple rows

后端 未结 2 775
执笔经年
执笔经年 2021-01-27 08:15

I have a simple form which is a textarea and I need to insert each lines in my textarea into a different rows in MySQL.

HTML code:


2条回答
  •  -上瘾入骨i
    2021-01-27 08:23

    Try this:

    $text = trim($_POST['textareaname']);
    $textAr = explode("\n", $text);
    $textAr = array_filter($textAr, 'trim'); // remove any extra \r chars
    
    foreach ($textAr as $line) {
        // Your sql Query here with $line as the string.
    } 
    

提交回复
热议问题