Forum Moderators: coopster

Message Too Old, No Replies

Can I display an SQL result in form fields

         

m8fyu

6:22 am on Aug 28, 2010 (gmt 0)

10+ Year Member



I'm writing a html form that I will use to update a particular table in my database.

My question is can I run a query on the table and populate the fields that have results back into their respective form fields?

I've done a few searches in a bid to find out more on the subject but all I seem to find is information on how to display results back in a table.

I want to be able to make changes and updates, as well as easily see which fields still need data in them.

Is this possible?

Anyango

6:41 am on Aug 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes very easy

for example if with your sql result you populate a variable

$email=$record["email"];

You can use this to populate your Email form field like this

<input type="text" id="email" name="email" value="<?php =$email;?>">

and similarly other fields.

And for drop down boxes and radio buttons you can use a bit of if else

Anyango

6:41 am on Aug 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



or if writing html via php


echo '<input type="text" id="email" name="email" value="'.$email.'">';

m8fyu

7:08 am on Aug 28, 2010 (gmt 0)

10+ Year Member



Thanks Anyango. I'll give it a go.

rocknbil

5:57 pm on Aug 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Recently discussed [webmasterworld.com], use your forms for both add and update, and put them in a function (at the very least.) see third post for an example.

m8fyu

1:21 am on Aug 29, 2010 (gmt 0)

10+ Year Member



Thanks Rocknbil, the link is great and has some good info available for exactly what I am trying to achieve. Thanks again.