Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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;

In reply to Re: How to get a placeholder to keep the current column value? by BUU
in thread How to get a placeholder to keep the current column value? by liz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-19 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found