TradeRaider
TradeRaider

Reputation: 754

Update the attributes/fields that have been changed PHP

I am building the profile section of a php site. It offers a profile edit section. Say, I have the details user_id, user_name, user_firstname, user_lastname,user_email in my $_SESSION variable.

So, if any user edits any of these attributes, by going to localhost/profile/edit, how should I go on about updating the database columns that have been changed?

ie 1. Should I compare the post data with my session variable and update only the changed fields? But I don't know how to implement this.

  1. Should I update all fields?

  2. SOme other standard way of doing things?

If you need more clarification, let me know.

Upvotes: 0

Views: 92

Answers (1)

Tomahock
Tomahock

Reputation: 479

Between update all fields and just on field it's up to you. In a REST perspective you should use a PUT to update the whole resource and a PATCH to update just one field of the resource. So i think is really up to you!

In any case the flow should be:

  • update the tables (one field or many)
  • update session

Upvotes: 3

Related Questions