/    Sign up×
Community /Pin to ProfileBookmark

How to pass only changed fields to sql UPDATE?

Trying to construct a sql statement to update field values contained in a form. I would like to only update the values that are changed. If the current $_POST[] values populated in the form are not changed, there is no need to add that field to the UPDATE statement… but i am not sure how to do this with javascript and pass only those values. Can someone help?

Some say that it is not worth the code processing to do this but I would like to do this if possible. I know that phpmyadmin works this way.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Gozzy82Mar 10.2010 — you can store the values in a session and check if the values you get from post are different ifso change it

or you can add all the values to a hidden input and compare with that or you add hidden inputs which you set to true/false when the input has been changed

something like

<input type="text" name="firstname" value="blaat" onclick="change(this.name);" />

<input type="hidden" name="firstname_hidden" value="0" />


function change(name){

document.getElementsByName(name + '_hidden')[0].value = '1';

}

on post check the hidden inputs and update accordingly

but i agree its too much work for such a thing and besides if you know phpadmin does it why dont you use the method you have seen in phpadmin?
Copy linkTweet thisAlerts:
@mellowauthorMar 10.2010 — Thanks for the help. I will try your suggestions.

I have not looked at the source code for phpmyadmin... only noticed that when I use it, it only posts changed-value fields.
×

Success!

Help @mellow spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...