http://qs321.pair.com?node_id=31073

Jonas has asked for the wisdom of the Perl Monks concerning the following question:

Hey folks,

I'm using a hash, %user_info, to make an update to a a database I've built. I have already connected to the database just fine.

$sth = $dbh->prepare(" Update tUser Set ? = ? Where UserId = $user_info{UserId} "); foreach $key(keys %user_info) { if ($key ne "UserId") { $sth->execute($key, $user_info{$key}); } } $sth->finish();
I get the error:
DBD::mysql::st execute failed: You have an error in your SQL syntax ne +ar ''LastName' = 'Smith' Where UserId = 1 ' at line 2 at /usr/usr_update line 197.
I'm positive that it's because the field is in quotes. Is there a better way to do this, or is there a command to take the quotes away?

Thanks in advance,
t