MySQL insert from a textarea to multiple rows

后端 未结 2 772
执笔经年
执笔经年 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条回答
  •  盖世英雄少女心
    2021-01-27 08:24

    This should work:

    $textarea = mysql_real_escape_string($_POST['url']);
    $array = explode("\n", $textarea);
    foreach ($array as $value) {
        mysql_query("INSERT INTO test (text) VALUES ('".$value."')") or die(mysql_error());
    }
    

提交回复
热议问题