sql >> Base de Datos >  >> RDS >> Mysql

Cómo insertar varias filas desde un área de texto en MySQL

Tienes que analizar el texto, buscando el carácter "enter":

<?php
if(isset($_POST['url'])){
    if(strpos($_POST['url'], "\n")){
        $entries = explode("\n", $_POST['url']);
    } else {
        $entries = array($_POST['url']);
    }
    // connect to DB here
    // then iterate over entries
    foreach($entries as $e){
        // build some type of Prepared Statement to protect from SQL Injection
        $q = "INSERT INTO table (col1) VALUES (?)";
        // bind $e to statements
        // Execute SQL statements
    }
    // close DB connection
}
?>