I’m writting a web app, I’m doing a html form with javascript to validate the data, I’m using a servlet to insert the data in a DB, but I need, when the form load, fill a select in the html form with the rows of a table in a MySql DB, I think I have to make a query in a ResultSet and then fill the select in the html form with this info, and then use the HttpServletResponse, but I have no idea how to make this
Share
Use PHP to access the database and then put it into the form. Something like this:
In this, the info array has all of the database data in it of the id. But of course you would change the values and stuff. Change table_name to the table name, and if you are going to do something in the URL like
?id=373384or something, then this will work. (I would assume you are doing it this way.) But, if it isn’t ‘id’, just change WHERE id=’$id’ to what is in the database to identify a line.$info[‘name’]; would be the “name” column in your table. But, you can change ‘name’ and stuff to what you have in your database.
Here is the form code to pre-fill it with data:
You would need to change a lot of this, but I’m sure you get the point of it. 🙂
Note: This is not a simple copy+paste script. You will have to do a lot of charing because I don’t know what your table values are and stuff.
If you have any questions, please do ask.