Jump to content


Photo

fill form fields to equal mysql table values


  • Please log in to reply
6 replies to this topic

#1 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 23 July 2006 - 06:46 PM

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


<?

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

?>



#2 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 23 July 2006 - 07:59 PM

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.


I don't understand the question.

#3 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 23 July 2006 - 08:14 PM

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.

#4 aerospc

aerospc
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 July 2006 - 08:27 PM

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>

#5 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 23 July 2006 - 08:31 PM

Your using extract() and trigger_error(), I can't imagine your not familair with the value attribute of the html input element..  ???

#6 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 23 July 2006 - 08:55 PM

I'm a rookie, everything I have learned is from tutorials, and some code is copied and edited.



#7 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 23 July 2006 - 09:09 PM

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... ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users