UPDATE table SET business = ? .. ^^^^^ this should be the table name users #### or die "Error Preparing:\n" . $stmt . "\nDBI returned: \n", $dbh->errstr; .. or die "Unable to execute query: " . $sth->errstr; #### sub update_insert_Record { warn("522 update_insert_Record"); my $post = $query->param("post"); return if ($post); my $user_id = $query->param('user_id'); my @form = qw(id username password pin position forename lastname business address1 address2 city state zip email phone_home phone_cell comments MJ MD DD DP); # UPDATE existing record my %newData = map{ $_ => $query->param{$_} } @form; #Recover existing values from database and fill variables my $stmt = 'SELECT * FROM users WHERE user_id = ?'; warn("statement = '$stmt'"); my $sth = $dbh->prepare($stmt); $sth->execute($user_id); my $oldData = $sth->fetchrow_hashref(); my @fields; my @values; # compare old v new for (sort keys %newData){ if ($newData{$_} ne $oldData->{$_}){ push @fields,"$_ = ?"; push @values,$newData{$_}; } } # skip if no change if (@fields == 0){ print "No update required\n"; } else { # build sql my $fields = join ',',@fields; my $stmt = "UPDATE users SET $fields WHERE user_id = ?"; #add id push @values,$user_id; warn("statement = '$stmt'"); # prepare and execute sql # print "$stmt\n(@values)\n"; $sth = $dbh->prepare($stmt); $sth->execute(@values); } }