Page 1 of 1

populate form fields from sql output

Posted: Mon Apr 12, 2010 7:01 am
by bakon
Hi,
is there any way how to populate a form with pred-defined values, based on SQL output ?
My piece of code is as follows:
....
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><td>Address: ", $row['address'], "</td></tr><td>City: ", $row['city'], "</td></tr>\n";
}
mysql_close ($conn);
?>
</td>
</table>
<td align=left valign=top >
<h4 align=center> To modify your contact information, fill out from below </h4>

<form method="post" action="update_v_ad.php">
<input type="Hidden" name="send" value="true">
<table>
<TR>
<TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Address:</font></TD>
<TD><input type=text name="address" ></TD>
</TR>
How can I get a form where input has pred-defined value pulled from sql query, so in case user don`t want to change address, there is no need form him to type address again..
Many Thanks!

Re: populate form fields from sql output

Posted: Mon Apr 12, 2010 7:15 am
by roders
Just echo the value in the address field.

Code: Select all

<input type="text" name="address" value="<?php echo $row['address'];?>">

Re: populate form fields from sql output

Posted: Mon Apr 12, 2010 7:58 am
by bakon
It works, Thanks !