in reply to Re^4: {KOHA}Parse XML and assign to variables.
in thread {KOHA}Parse XML and assign to variables.

I'm trying to work with you to reduce your program to a very minimal example that exhibits the error but does not rely on modules that are maybe not installed.

The program you show needs LWP::UserAgent, CGI, XML::Parser (not XML::Simple!) and various C4 modules. Please work on removing as many modules as possible from that list. Also, consider replacing the AddMember function by something that just outputs the values so that we can easily check if the error happens before or after writing to the database.

Replies are listed 'Best First'.
Re^6: {KOHA}Parse XML and assign to variables.
by scolife (Novice) on Sep 15, 2015 at 12:24 UTC
    I am using template toolkit. So I can pass values to template. And It shows normal

    When I call AddMember function

    It inserts hash(HASH(0x5777c30) .. etc) I removed some module usage from code so
    #!/usr/bin/perl use CGI; use C4::Auth; use C4::Output; use C4::Context; use XML::Simple; use C4::Members; use LWP::UserAgent; use utf8; my $input = new CGI; my $remoteip= $input->remote_host(); my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "members/addfromsisi.tt" +, query => $input, type => "intranet", authnotrequired => 0, flagsrequired => {borrowers => 1}, }); my $rfid= $input->param('rfid'); my $op= $input->param('op'); # request my $ua = LWP::UserAgent->new; my $response = $ua->get("https:/************/studentservice/se +rvice.asmx/give_to_koha_byStudentCard?cardNR=$rfid&ip=$remoteip"); my $xml=$response->content; # parse my $xs = new XML::Simple(keeproot =>0,searchpath => ".",forcea +rray => 1,); my $ref = $xs->XMLin($xml); my $firstname=${$ref->{firstname}}[0]; my $lastname=${$ref->{lastname}}[0]; my $sisiid=${$ref->{sisiid}}[0]; my $school=${$ref->{school}}[0]; my $program=${$ref->{program}}[0]; my $registerNr=${$ref->{registerNr}}[0]; my $userStatus=${$ref->{userStatus}}[0]; my $usertype=${$ref->{usertype}}[0]; my $photo=${$ref->{photo}}[0]; my $branch=${$ref->{abbrevm}}[0]; my $op= $input->param('op'); # save when op= "save" my %newdata; if($op eq "save"){ %newdata =("cardnumber"=>"$rfid", "surname"=>"$lastname", "firstname"=>"$firstname", "initials"=>"$registerNr", "address"=>"$program", "userid"=>"$sisiid", "categorycode"=>'ST', "branchcode"=>'EZS', "password"=>'aaaaaaa' ); my $borrowernumber=&AddMember(%newdata); if (defined $borrowernumber) { my $q = new CGI; print $q->redirect(-uri=>"moremember.pl?borrowernumber +=$borrowernumber"); } }# save end $template->param( rfid=>$rfid, photo=>$photo, firstname=>$firstname, lastname=>$lastname, sisiid=>$sisiid, school=>$branch, program=>$program, registerNr=>$registerNr, userStatus=>$userStatus, usertype=>$usertype, remoteip=>$remoteip, op=>$op, res=> $imgfile, ); output_html_with_http_headers $input, $cookie, $template->output;

      Your code still won't run for me because it still requests data from a website and uses the C4 modules and calls AddMember(). Please reduce your code further by removing the need for LWP::UserAgent, the C4 modules, CGI, Template and the AddMember function.

        #!/usr/bin/perl use CGI; use XML::Simple; use XML::Parser; use LWP::UserAgent; my $input = new CGI; # request my $ua = LWP::UserAgent->new; my $response = $ua->get("https://sisi.num.edu.mn/studentservic +e/service.asmx/give_to_koha_byStudentCard?cardNR=126186D2&ip=10.0.120 +.1"); my $xml=$response->content; # parse my $xs = new XML::Simple(keeproot =>0,searchpath => ".",forcea +rray => 1,); my $ref = $xs->XMLin($xml); my $firstname=${$ref->{firstname}}[0]; my $lastname=${$ref->{lastname}}[0]; my $sisiid=${$ref->{sisiid}}[0]; print "$firstname $lastname $sisiid";