This is a tad late and perhaps superfluous, but why are you bothering with all this dynamic sql and so on? When you execute an update in mysql it only changes the columns you specify, yes? So just leave all the other fields blank and let the database handle it. Eg, assuming you have a hash with the key being the column name and the value being the, uh, value, then just do something like:
my $sql='UPDATE table SET '.join',',map {"$_=".quote($hash{$_})} keys
+%hash;
Then, in your example, you just end up with sql looking like:
UPDATE table SET phone='456'
Obviously you need a where statement and so on, but thats simple. This way you only touch the fields you want to change and you don't need to worry about restoring the old values and fun stuff like that. The only problem I see is if they wanted to submit say, an empty field and not update the value which would probably require something slightly more complicated then a nice map, but perhaps you could chain maps:
map {"$_=".quote($hash{$_})} grep defined $hash{$_},keys %hash;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.