Insert value in sql table using "part" of the form

Asked

Viewed 22 times

-1

I have a form for registering revenue. When I finish the registration, the revenue is added in the table "recipes". 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 queries in the database, as it writes the ingredient it brings the name and when clicking on the name it adds in the ingredients field.

So I wanted, if he didn’t find the ingredient, by clicking Add ingredient, he would take the value that is in the ingredient field and add in the table "ingredients".

  • Enter the code of addingrediente

  • just make a if return of the ingredients query, and check whether the result set has Count = 0

  • And if the field is empty?

  • If you do not find anything the field will be empty. What does Javascript have to do with it? You are using Ajax?

1 answer

1

Add in your search script, the action of registering the ingredient being searched for in the bd when the search result return 0 && Empty($ingredient) == false. Therefore, it will register 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 enter the value of the ingredient in the textarea would look something like this using only Javascript: "Document.getElementById(field). innerHTML=ingredient"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.