I am trying to use JSON and sending back temporarily to an Iframe to see what is returned.

#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" . $stm +t . "\nDBI returned: \n", $dbh->errstr; $sth->execute () or die "Unable to execute query: " . $sth->errstr +; warn("Finished sub search record"); generateResponseHash($sth); }

If I intercept at this point and send to html (form for testing) I get back what I want in table format.

The problem is getting JSON result back and dealing with the error log entry:

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.

sub generateResponseHash{ my $sth = shift; my ($user_id, $username, $password, $pin, $position, $forename, $la +stname, $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"}, ); }

I get error or warning which ever it is stating:

[Mon Mar 12 12:38:34 2018] update_tables.cgi: statement = 'SELECT * F +ROM 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 reco +rd 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: 'H +ASH(0x287bd08)' at update_tables.cgi line 593. Odd number of elements in hash assignment at update_tables.cgi line 62 +6 (#1) (W misc) You specified an odd number of elements to initialize a h +ash, which is odd, because hashes come in key/value pairs. [Mon Mar 12 12:38:34 2018] update_tables.cgi: Odd number of elements i +n 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.

from the code below:

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); }

In reply to Re^2: CGI Action call by tultalk
in thread 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.