Are you wanting to execute the query as soon as the user changes the value, or after the page is submitted?
Since HTTP is a stateless protocol, you'll have to embed some "previous value" type of information. One common way to do this is to include hidden form fields for each element that contain the default values for fields. Quick example:
<input type="text" name="foo" value="bar">
<input type="hidden" name="foo_value" value="bar">
After the form is submitted, you can check to see if the value was altered like so:
if($_POST['foo'] != $_POST['foo_value']) { // "foo" was changed by the user