Jump to content


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


Up Date User Information

Recommended Posts

Below is code that I'm using to display a users information . I'm trying to figure out how I can change this so that it can be used to update a users information via a form call UpdateMyInformation.php

thank you for any help

<?php session_start(); ?>

<title>Get My Info</title>


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

  trigger_error("<p>SQL ERROR:<br>".mysql_error()."<br>Query: $query</p>",
elseif(mysql_numrows($result) != 1)
  trigger_error("<p>DB ERROR: There were multiple matches on this User ID</p>",
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");
   echo <<<END
<b>$user_first_name $user_last_name</b><br>
Date of Birth: $user_DOB<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>



Share this post

Link to post
Share on other sites
updateinfo.php can be something like this:

<? //mysql query calling for the data you want to be updated to fill in the values in the form below ?>
<form name="update" action="process.php" method="post">
Field Name : <input type="text" name="field_name" value="<? echo $row->field_value;?>">
Field Name1 : <input type="text" name="field_name1" value="<? echo $row->field_value1;?>">
Field Name2 : <input type="text" name="field_name2" value="<? echo $row->field_value2;?>">
on the process.php page, something like this:

<? if ($_POST['field_name']){
mysql_query("UPDATE `tablename` SET `field_name`='$_POST[field_name]', `field_name1`='$_POST[field_name]1', `field_name2`='$_POST[field_name2]'") or die (mysql_error());
echo "fields updated!";

again, this is very basic..it bypasses other common and useful things you may want to use like check for blank/invalid entries, strip any tags someone may enter into a form field, check for duplicates (like duplicate username or email if that is what's updated), etc etc.

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.