Click to See Complete Forum and Search --> : fill form with value in mysql table


kproc
07-22-2006, 10:26 PM
Below is the code for a field on a form.

The coresponding value is stored in my database. the column name is street.

how would I pull the value from the database and populate the form field.

Note: there are 30 fields


<tr>
<td></td>
<td>Street Address:</td>
<td><input id="Street_address" name="Street_address" type="text">
</tr>

kproc
07-23-2006, 11:57 AM
The record in the table is found using the user id

I have this code which diplays the users info. I believe I need to assign the row values to variables so that I can set the form values


include 'db.php';

$username = $_SESSION['username'];


// note, if userid is not a numeric type column, then $userid must be quoted
$query = "SELECT * FROM users WHERE username = '$username'";
$result = @mysql_query($query);

if(!$result)
{
trigger_error("<p>SQL ERROR:<br>".mysql_error()."<br>Query: $query</p>",
E_USER_WARNING);
}
elseif(mysql_numrows($result) != 1)
{
trigger_error("<p>DB ERROR: There were multiple matches on this User ID</p>",
E_USER_WARNING);
}
else // we got exactly one match on the User ID
{
echo "<b><center>Database Output</center></b><br><br>";

// only 1 match, so we don't need a loop
$row = mysql_fetch_assoc($result);
extract($row, EXTR_PREFIX_ALL, "user");
mysql_close();

echo <<<END

<b>$user_first_name $user_last_name</b><br>
Date of Birth: $user_DOB<br>
<b>Address</b><br>
Street Address: $user_Street_address<br>
Other Mailing Information: $user_post_office_box<br>
City: $user_city <br>
Province: $user_province<br>
Postal Code: $user_postal<br>
Home Phone Number: $user_home_phone<br>
Email Address: $user_email_address<br>
Family Relationship: $user_familyRelationship<br>

<hr><br>
END;
}

?>

NogDog
07-23-2006, 12:18 PM
The code sample looks OK to me at a quick glance. Is it working, or is there a particular symptom if it is not?

kproc
07-23-2006, 12:58 PM
It works great, I want to change it some how so that I can set the table values to variables and use them to set form field values.