in reply to Re^3: New CGI Action Call
in thread New CGI Action Call
UPDATE table SET business = ? .. ^^^^^ this should be the table name users
If you add RaiseError=>1 to your connect statement like this
my $dbh = DBI->connect($dsn, $user, $pw, { RaiseError=>1 } );you don't need all those or die statements
or die "Error Preparing:\n" . $stmt . "\nDBI returned: \n", $dbh->errs +tr; .. or die "Unable to execute query: " . $sth->errstr;
update : changed first @fields to @formsub 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); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: New CGI Action Call
by tultalk (Monk) on Mar 25, 2018 at 17:00 UTC | |
by marto (Cardinal) on Mar 25, 2018 at 17:47 UTC | |
by tultalk (Monk) on Mar 26, 2018 at 00:03 UTC | |
by marto (Cardinal) on Mar 26, 2018 at 09:26 UTC | |
by poj (Abbot) on Mar 26, 2018 at 06:54 UTC |