tags:

views:

46

answers:

3

When users edit their account, I want to display a confirmation page that shows their updated information with the fields that they changed in bold. Is there a mysql statement that allows you to select the fields that a user changes? If not, how exactly can I achieve this

Ex:

(editaccount.php)
first_name: bob
last_name:  builder
email: [email protected]

When they change say their first name to "james", the confirmation page shows their first name in bold because they changed that but the other areas are still normal text.

first_name: <b>James</b>
last_name: builder
email: [email protected]
+3  A: 

I would handle it at the application level, in php. Before committing the update, simply pull the data from the database, compare each field with the submitted data, and handle each inequality to your liking.

Daniel Vassallo
alright that sounds simple enough. thanks.
ggfan
+3  A: 

You need to compare the fields against the old data yourself.

very basic example:

$old_user_data = <fetched from db>;
$new = $_POST;
$changed = array();

foreach ($old_user_data AS $field => $value) {
  if ($new[$field] != $value) {
     $changed[] = $field;
  }
}

print_r($changed); // array contains all fields that were changed
Joel L
+2  A: 

I don't know if MySQL can tell you which fields were altered. Interested to hear how though. In PHP you can simply compare the information before and after the update.

// select current info, store it in $before, e.g.
// then go through the posted values
$changed = array();

foreach ($_POST as $key => $value) {
  // compare new value against the previous one
  if ($before[$key] != $value) {
    $changed[] = $key;
  }
}
Alec