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;
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); } }
update : changed first @fields to @form
poj

In reply to Re^4: New CGI Action Call by poj
in thread New CGI Action Call by tultalk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.