I'm creating a recipe site, where the ingredients will be individually registered in a table, referring to the recipe id, example of how the tables are:
ptp_receitas
id|nome
1 |receita de feijão
ptp_receitas_ingredientes
id|id_receita|ingrediente
1 | 1 | feijão
2 | 1 | bacon
3 | 1 | cebola
I created a form that inserts the values into the database, but I do not know how to insert each ingredient into a new row.
I thought of something with ajax, putting an "ingredient" input that adds the values in a multiple select, and after registering the recipe, it takes every value from that list and inserts a line in ptp_receitas_ingredientes, something like this:
<input id="ingrediente">
<button id="add_ingrediente" type="button">Adicionar Ingrediente</button>
<select id="ingredientes" multiple>
</select>
<input id="nome_receita">
<button id="cadastrar_receita" type="submit">Cadastrar Receita</button>
Is the line of reasoning for my need the same? Or is there another way to do that?
Thank you!