Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php check form fields for a change of any type

Posted on 2011-09-03
3
Medium Priority
?
304 Views
Last Modified: 2012-06-27
I have a project nearing completion that allows members of an organizatin to login and review their membership records, make changes and submit them to a mysql database for update. I have several fields that might be modified by the user and a few that are read only and wont be modified. I am using SESSION and POST to pass variable from page to page and all of that is working well. I am coding the mysql update function now and I want to detect the submitted form fields for a change from the initial value (i.e the user modified their info in a field) and then based on knowing which fields had a change I will run the correct update query for those specific updates and avoid running an update query on fields that had no change. Again I know the value of all of the variables coming from the form fields so I am not needing help on that just need to know Is there a change or not.  I know there are a couple of javascript event handlers that can be used but I want to avoid javascript in this particular project (I already have some JS but want to avoid it here). I am looking at compairng the intial values for each field as they are specific to the user that is logged in and were extracted from the database and placed in varaibles that were displayed in forms. After review,  the user will either make  changes and submit, log out or even submit with no changes. I need to know if  change(s) or no change was made to each form field. Again I want to do this in php if possible. Im looking for a tight method that I can apply to get the information as described. I'm in a bit of a hurry as always so anyone with ideas or solutions please throw them this way.
0
Comment
Question by:Ron McCain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
ghodder earned 750 total points
ID: 36479620
The way I normally do it is store the current values in a cookie or session after I pull them from the database, then after they submit the form I check the values submitted against what was previously stored and if there are changes I update the database. I like using cookies/session because they're easily encrypted in 1 hit if there are password fields involved. You could also just generate hidden form fields with the current values if you wanted to avoid cookies.

If one of the fields is a password don't output the password in plain text as anyone who viewed the page source would obviously be able to see it. Either store a hash in the hidden field or just assume that if they have typed a new password into your 2 password fields and both password fields are equal they must want to change their password from whatever they currently use.
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 750 total points
ID: 36481325
One design pattern that I have used successfully goes something like this:

Put the client identifier into the URL GET argument string, or store it in a cookie.  You can then give the client a link that says "Update my information."  

Use the client identifier to look up the client record and use the client record to pre-populate the HTML form.

When the client submits the form. write the submitted form information into the data base.  You do not need to detect what changed - just store the information that the client presented (subject to your own business rules, of course) and then present the form again.  Once your client is satisfied, she will navigate away.  Many high-level web sites do this, including Twitter, Facebook, etc.
0
 

Author Closing Comment

by:Ron McCain
ID: 36483188
I settled on using seesion array to test initial values from database against POST values, seems to work well. I got great info from both experts so I split the accepted solution points between them. Thanks for the fast response folks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question