I’ve got a form and would like to populate it with mysql data IF such data exists. But what I’ve come up with on my own seems very cumbersome and I wondered if there’s any better way to do it:
echo "<tr><td>First Name:</td><td><input type='text' name='firstname' size='40' value='";
if ($row1['firstname']) { echo $row1['firstname']; } else echo '';
echo "' /></td></tr>";
echo "<tr><td>... (etc)
Just wondered if this is a good way to do this or if there’s a shorthand or “better” way.
Thank you for any suggestions or help!
The way I have done it in the past is to use mysql_fetch_assoc() to return an associative array in the top of my php document, then throughout the html of the form, insert
into the value attribute.
EDIT: Do NOT use
mysql_functions. Both PDO and MySQLi have equivalent functions that should be used instead. Google them, use them.