#Search Records & Return Found 3 buttons # 0 Member ID # 1 Last Name # 2 Business Name elsif ($action eq "updatetable_167"){ warn("Entered updatetable_167"); my $kind = $query->param('kind'); my $searchterm = $query->param('searchterm'); my @row; warn("searchterm = '$searchterm'"); # $searchterm = "'" + $searchterm + "'"; my $searchfield = ""; if ($kind == 0) { $searchfield = 'user_id'; } if ($kind == 1) { $searchfield = 'lastname'; } if ($kind == 2) { $searchfield = 'business'; } # SELECT * FROM users WHERE lastname = 'DeWitt' my $stmt = "SELECT * FROM users WHERE $searchfield = $searchterm"; warn("statement = '$stmt'"); #my $sth = $dbh->prepare ($stmt); my $sth = $dbh->prepare ($stmt) or die "Error Preparing:\n" . $stmt . "\nDBI returned: \n", $dbh->errstr; $sth->execute () or die "Unable to execute query: " . $sth->errstr; warn("Finished sub search record"); generateResponseHash($sth); } #### sub generateResponseHash{ my $sth = shift; my ($user_id, $username, $password, $pin, $position, $forename, $lastname, $business, $address1, $address2, $city, $state, $zip, $phone_home, $phone_cell, $email, $comments, $MJ, $MD, $DD, $DP) = @_; my $count = $sth->rows; $count = 0; $sth->execute () or die "Unable to execute query: " . $sth->errstr; while (my $ref = $sth->fetchrow_hashref ()){ # #warn("generateResponseHash line 587 ref: '$ref'"); hash_display_listing ($ref); ++$count; } $sth->finish (); completeResultHash(%hash_record); } #### sub hash_display_listing{ my $ref = shift; warn("hash display_listing: '$ref'"); %hash_record = ( 'user_id' =>$ref->{"user_id"}, 'username' =>$ref->{"username"}, 'password' =>$ref->{"password"}, 'pin' =>$ref->{"pin"}, 'position' =>$ref->{"position"}, 'forename' =>$ref->{"forename"}, 'lastname' =>$ref->{"lastname"}, 'business' =>$ref->{"business"}, 'address1' =>$ref->{"address1"}, 'address2' =>$ref->{"address2"}, 'city' =>$ref->{"city"}, 'state' =>$ref->{"state"}, 'zip' =>$ref->{"zip"}, 'phone_home'=>$ref->{"phone_home"}, 'phone_cell'=>$ref->{"phone_cell"}, 'email' =>$ref->{"email"}, 'comments' =>$ref->{"comments"}, 'MJ' =>$ref->{"MJ"}, 'MD' =>$ref->{"MD"}, 'DD' =>$ref->{"DD"}, 'DP' =>$ref->{"DP"}, ); } #### [Mon Mar 12 12:38:34 2018] update_tables.cgi: statement = 'SELECT * FROM users WHERE user_id = 15' at update_tables.cgi line 377. Finished sub search record at update_tables.cgi line 383. [Mon Mar 12 12:38:34 2018] update_tables.cgi: Finished sub search record at update_tables.cgi line 383. hash display_listing: 'HASH(0x287bd08)' at update_tables.cgi line 593. [Mon Mar 12 12:38:34 2018] update_tables.cgi: hash display_listing: 'HASH(0x287bd08)' at update_tables.cgi line 593. Odd number of elements in hash assignment at update_tables.cgi line 626 (#1) (W misc) You specified an odd number of elements to initialize a hash, which is odd, because hashes come in key/value pairs. [Mon Mar 12 12:38:34 2018] update_tables.cgi: Odd number of elements in hash assignment at update_tables.cgi line 626. completeResultHash line 631 at update_tables.cgi line 627. [Mon Mar 12 12:38:34 2018] update_tables.cgi: completeResultHash line 631 at update_tables.cgi line 627. after jason_str print at update_tables.cgi line 632. #### sub completeResultHash{ my %hash = shift; warn("completeResultHash line 631"); my $json_str = encode_json(\%hash); print "$json_str"; warn("after jason_str print"); exit(0); }