in reply to Re^10: CGI Action call
in thread CGI Action call
In addition to Corion's comments the first line of this sub is incorrect, the scalar $ref will be 1, the count of elements in @_
sub hash_display_listing{ # my $ref = @_; my ($ref) = @_; # or # my $ref = shift ;
$sth->execute($searchterm) or die "Unable to execute query: " . $sth->errstr; warn("Finished sub search record"); $result = generateResponseHash($sth);
You are calling $sth->execute() twice, first time with a parameter and again in generateResponseHash($sth) without parameter
Breaking long code into subroutines is usually good practice but be careful not to overdo it :)
elsif ($action eq "updatetable_167"){ warn("Entered updatetable_167"); my $kind = $query->param('kind'); die "ERROR \$kind='$kind'" if ($kind < 0 || $kind > 2 ); my $searchterm = $query->param('searchterm'); warn("\$searchterm = '$searchterm'"); my $searchfield = ['userid','lastname','business']->[$kind]; warn("\$searchfield = '$searchfield'"); my $stmt = "SELECT * FROM users WHERE $searchfield = ?"; warn("\$stmt = '$stmt'"); my $sth = $dbh->prepare($stmt); $sth->execute($searchterm); warn("Finished sub search record"); my $count = $sth->rows; warn("\$count = '$count'"); if ($count == 0) { warn("Failed Search: '$searchfield' equal to '$searchterm' "); } else { my $ref = $sth->fetchrow_hashref(); my $hashref = hash_display_listing($ref); completeResultHash( $hashref ); } $sth->finish (); } sub hash_display_listing{ my ($ref) = @_; my %hash = %$ref; print Dumper \%hash; return \%hash; } sub completeResultHash{ my $hashref = shift; warn("completeResultHash line 631"); my $json_str = encode_json($hashref); print $json_str; warn("after jason_str print"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^12: CGI Action call
by tultalk (Monk) on Mar 14, 2018 at 20:34 UTC | |
by Corion (Patriarch) on Mar 14, 2018 at 20:44 UTC | |
by tultalk (Monk) on Mar 15, 2018 at 08:41 UTC | |
by Corion (Patriarch) on Mar 15, 2018 at 08:48 UTC | |
by poj (Abbot) on Mar 14, 2018 at 20:55 UTC |