Question by Pure Kenergy: Posting data from a MySQL database into a form with PHP?
I am working on a client’s website that has forms for their customers. I have a login section already created, and a MySQL database will store all the client information. The login is set up to automatically redirect the user to a certain page based on their login, so in this case it will only show their forms. What I want to do is have their data such as business name, name, address, phone, etc. auto-fill into the appropriate fields so all they have to do is enter what they are writing about. Sort of to give the feel of it being customized just for the client. So when they open a form all the information about them is already in the fields (i.e. the business name field will already have their company’s name in the field). Then when they enter what they are writing about they hit submit and it goes through email (which is also already done).
Can someone direct me or tell me how you code with PHP to pull records from the MySQL database from just the specific client’s information to fill in the form fields I want filled in with the appropriate info? I see all kinds of web pages related to posting data to MySQL from a form, which I know how to do. The retrieval is what I am having issue with.
Any help would be greatly appreciated, and best answer will get 10+ points. If you need further clarification on what exactly I’m trying to do let me know.
Answer by Andrew A
pretty extensive question, i would recommend bookmarking phpbuilders.com their forums is where I taught myself php from scratch.
first you have to call up the mysql db:
$ link = mysql_connect (“server address”, ‘username’, ‘password’) or die (“Could not connect”);
then you get your record:
$ result = mysql_query(“select * from tablename WHERE unique_id=’whatever’”);
$ row = mysql_fetch_object($ result);
then in your form you just put the value into it: