
lukdk
Novice
Jul 8, 2010, 2:56 PM
Post #1 of 2
(5842 views)
|
problem passing the $sth variable to another sub
|
Can't Post
|
|
Hello there, I've got a problem passing the $sth variable to another sub: this is the sub that gives problems:
sub display_items { my ($sth, $min, $max) = @_; if (!$min){ $min=0; } if (!$max){ $max=50; } else { $min = $max; $max = $max + 50; } my $counter = 0; my $previous_url = sprintf("%s?choice=previous&min=%i&max=%i&sth=%s", url(), $min, $max,$sth); my $next_url = sprintf("%s?choice=next&min=%i&max=%i&sth=%s", url(), $min, $max,$sth); print "this procedure is called $min $max $sth"; while (my $row = $sth->fetchrow_hashref()){ if ($min <= $counter && $counter <= $max) { display_entry ($row); } $counter++; } if ($counter == 0){ print p("no items were found in the database"), br(); } print br (), a({-href => $previous_url}, "previous")," ", a({-href => $next_url}, "next"), br(); } When i call this sub with the following code it works just fine:
sub submit_param { my ($dbh ,$search, $operator, $searchvalue) = @_; my $sth; $sth = $dbh->prepare ("SELECT * FROM squid WHERE $search = ? ORDER BY id"); $sth->execute($searchvalue); display_items($sth); } but when i call it from the internetl link that i'm printing in the display_items sub, I get an error. This is the code that gets called when clicking on the link:
}elsif ($choice eq "next"){ display_items(param("sth"), param("min"), param("max")); } this gets printed on the website: this procedure is called 50 100 DBI::st=HASH(0x85da454) this is the error i see in the apache log file: [Fri Jul 09 01:50:45 2010] [error] [client 192.168.0.52] main::update_url() called too early to check prototype at /var/www/localhost/cgi-bin/test.pl line 32., referer: http://192.168.0.52/cgi-bin/test.pl?choice=update [Fri Jul 09 01:50:45 2010] [error] [client 192.168.0.52] Can't locate object method "fetchrow_hashref" via package "DBI::st=HASH(0x85da454)" (perhaps you forgot to load "DBI::st=HASH(0x85da454)"?) at /var/www/localhost/cgi-bin/test.pl line 118., referer: http://192.168.0.52/cgi-bin/test.pl?choice=update and this is the error i get when i call ./test.pl choice=next Use of uninitialized value in sprintf at ./test.pl line 115. Use of uninitialized value in sprintf at ./test.pl line 116. Use of uninitialized value in concatenation (.) or string at ./test.pl line 117. Can't call method "fetchrow_hashref" on an undefined value at ./test.pl line 118.
|