Insert value into sql table using form "part"

-1

I have a recipe form. When I complete the registration, the revenue is added in the "receipts" table. All ingredients are also in a separate table called "ingredients".

My form looks like this:

<form>
<input type="text" name="receita" id="receita">
<input type="text" name="ingrediente" id="ingrediente">
<button id="addingrediente">Adicionar ingrediente</button>
<input type="textarea" name="ingredientes" id="ingredientes">
</form>

I already have a script that does query in the database, as it writes the ingredient it brings the name and when clicking on the name it adds in the field ingredients.

So he wanted it, if he did not find the ingredient, by clicking Add Ingredient, he would take the value that is in the ingredient field and add in the "ingredients" table.

    
asked by anonymous 01.05.2018 / 04:45

1 answer

1

Add in your search script the action of registering the ingredient being fetched in the bd when the search result returns 0 & empty ($ ingredient) == false . Therefore, it will record the value of the ingredient only if the ingredient was not found in the search and its value is different from empty. Finally, just use Ajax to insert the value of the ingredient in textarea would look something like this using just JavaScript: "document.getElementById (field) .innerHTML = ingredient"

    
01.05.2018 / 05:56