Jump to content

Archived

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

proctk

fill form fields to equal mysql table values

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]

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
I want the form fields value to be set but a value in the table.

the form field Date of Birth would be populated with the persons DOB in the database.

Share this post


Link to post
Share on other sites
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>

Share this post


Link to post
Share on other sites
Your using extract() and trigger_error(), I can't imagine your not familair with the value attribute of the html input element..  ???

Share this post


Link to post
Share on other sites
I'm a rookie, everything I have learned is from tutorials, and some code is copied and edited.

Share this post


Link to post
Share on other sites
Ok, might I suggest you leave the MySQL tutorials for what they are for little while and do some basic html and forms tutorials first? You can't drive a car without wheels... ;)

Share this post


Link to post
Share on other sites

×

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.