PHP break list items "li" into variables to add to table MYSQL

0

I have a form with <textarea> with the following value:

<textarea id="lista-ingredientes" name="lista-ingredientes">
 <ul>
  <li>sal</li>
  <li>pimenta</li>
 </ul>
<textarea>

I need to send the form, PHP "break" the items of <li> into separate variables to add a line of each item, what I have is this, but it inserts everything in a single line:

$sql = "INSERT INTO receitas_ingredientes (id, ingrediente) VALUES ('NULL', ".$_POST['lista-ingredientes'].")";

I think it's something using explode and foreach, but I'm not very knowledgeable and could not mount

    
asked by anonymous 11.10.2017 / 14:49

1 answer

-2

You could do the listing by separating only with commas, it's much easier to fill in the textarea for the user and easier for you to make an explode with trim. You can also ask the user for only a line break between items, and the same way the comma exploits works:

ex1: " sal, pimenta, tompero, ..."
    $lista = explode(',',$_POST['texto']);

  ex2:
  sal
  pimenta
  tompero


$lista = explode('\n',$_POST['texto']);
    
11.10.2017 / 15:04