Jump to content

fill form fields to equal mysql table values


proctk

Recommended Posts

Hi

I have a form that is used to update registered users information.  I want the form to populate with the users information from the database table so that they can see current info before updating

I use the below code to display the logged in regestered users information but I cannot figure out how to assign the users information to variables that i can set to equal form values.

any help is great


code to get users information

[code=php:0]

<?

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;
}

?>

[/code]
[quote author=proctk link=topic=101575.msg402121#msg402121 date=1153680368]
I use the below code to display the logged in regestered users information [b]but I cannot figure out how to assign the users information to variables that i can set to equal form values.[/b]
[/quote]

I don't understand the question.
Does the following help...?

<form>
First Name &nbsp;<input type="text" name="usrfn" value="<?php print($user_first_name);?>"><br><br>
Last Name&nbsp;<input type="text" name="usrln" value="="<?php print($user_last_name);?>"><br><br>
<input type="submit" value="Update">
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.