How do select in postgres from an html field and use the return to fill in the other fields?

Asked

Viewed 527 times

2

Basically I have no experience with html, php or javascrip and I’m trying to turn myself into what you ask me here. The problem is this:

I have to make a registration page where the user selects a base year and if the record exists in the data group (postgres) it fills the fields with the data to update, and if it does not exist the fields remain empty to add the record. They are annual parameters, so we can already conclude that you can only have one registration per year. OBS.: Everything via Post.

I already have the code that makes the connection with the BD, only include where you need, and I also have a slight notion of sql commands, it is not so difficult. I really wanted an orientation, I have no idea what to research or where to start looking. I don’t want codes or anything (unless it’s for example, it helps a little), I really wanted to know what I need to learn to be able to do this, even because it is a very general doubt.

1 answer

1

I advise you to read AJAX with JQUERY.

The flow will be more or less the following:

  1. User enters the date.
  2. With JQUERY and its events (onkeypress, up etc) checks whether the date is complete.
  3. If complete, call a PHP script using ajax (https://api.jquery.com/jquery.post/).
  4. In this PHP script you will query your database (SELECT * FROM table WHERE data = '$data').
  5. If this query returns a line or not, create a JSON with the result
  6. With JSON created, just give it an "echo" Ex.: echo $json.
  7. With this our ajax will receive this JSON in the return, (Success function), in the return you do the data processing. Tip: From a read on the W3SCHOOLS website.
  8. Treating the data we set the values in inpunts we want.

A basic example making a similar flow: https://www.tutorialspoint.com/jquery/ajax-jquery-post.htm

Browser other questions tagged

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