I am trying to use json data as parameters in a mysql store procedure. I am getting a 502 error when i send my post to my perl script. If I manually enter the parameters in my script it works, so i have narrowed down my issue to $sth->execute($input->{to}, $input->{from}, $input->{id}, $input->{body});

use strict; use warnings; # # need CGI, JSON, # MIME::LITE for email, # and DBI/DBD::mysql for DB operations. # use CGI (); use JSON (); use DBI; use DBD::mysql; use MIME::Lite; # # Declare variables # my ($status, $email, $input); my $q = CGI->new; my $json = JSON->new->utf8; if ($q->param('POSTDATA')) { $input = $json->decode( $q->param('POSTDATA') ); } else { &SimpleJSONResponse("error","no JSON data found"); exit(0); } # # test that all sms values exist # if not, return error # unless (($input->{to}) && ($input->{from}) && ($input->{body}) && ($in +put->{id})) { # # if we don't get the required fields from flowroute, # return an error # &SimpleJSONResponse("error","required fields not present"); } else { # # we received the required fields from flowroute # connect to database # my $data_source = "DBI:mysql:database=flowroute;host=localhost"; my $user = "user"; my $password = "password"; my $dbh = DBI->connect($data_source, $user, $password) or die &Simp +leJSONResponse("error","cannot connect to db"); # # run stored procedure add_sms # stores sms to database and returns the email address # my $sql = "call add_sms(?, ?, ?, ?)"; my $sth = $dbh->prepare($sql) or die &SimpleJSONResponse("error","c +annot prepare sql"); $sth->execute($input->{to}, $input->{from}, $input->{id}, $input->{ +body}); } # # Subroutines # sub SimpleJSONResponse() { my($key, $value) = @_; print $q->header(-type => "application/json", -charset => "utf-8"); print $json->encode({ $key => $value }); }

In reply to using json post in mysql stored procedure by mhanna2755

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.