in reply to Re: Re: Re: Re: Re: No results from script
in thread No results from script

Hi,

Well, I made the modifications. When I run the script, I'm receiving compilation errors. Unfortunately, I'm not able to see these errors on the server.

Here's the modified code. Maybe you'll be able to spot something.

Thanks for your help.
#!/usr/bin/perl -Tw use CGI qw(:standard); use strict; use lib qw(/export/ext2/www/bartellmachinery/library); use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard escapeHTML); use WebDB; my $customer_id; $customer_id = param("customer_id"); print header(), start_html (-title => "Order Tracking System", -bgcolo +r => "white"); my $choice = lc (param ("choice")); if ($choice eq "submit") # customer submitted order number { my $customer = get_customer($customer_id); print_results ($customer); } else { print p (escapeHTML ("Logic error, unknown choice: $choice")); } print end_html(); sub get_customer { my ($customer_id) = @_; my $dbh = WebDB::connect (); my $sth = $dbh->prepare ("SELECT * FROM Shipments WHERE customer_id = +?"); $sth->execute($customer_id); while (my $track_ref = $sth->fetchrow_hashref ()){ push(@customer, $track_ref); } return(\@customer); } sub print_results { my $customer = @_; print table ({-border => 0}, Tr ({-align => "CENTER", -valign=>"TOP", -BGCOLOR=>"silver", -st +yle=>"font-family: verdana; font-size: 10pt;"}, th ({-width=>"50"},("Customer ID")), th ({-width=>"50"},("Carrier")), th ({-width=>"90"},("Tracking Number")) + )); foreach my $row (@$customer) { print table ({-border => 0}, Tr ({-valign=>"center", -style=>"font-family: verdana; font-size: +10pt;"}, td ($row->{customer_id}), td ($row->{carrier_id}), td ($row->{tracking_number}) )); } print start_form (-action => "http://wwwapps.ups.com/tracking/tracking +.cgi", -method => "POST"), table ( Tr ( td ("UPS Tracking Number:"), td (textfield (-name => "tracknum")) ), ), submit (-name => "choice", -value => "Track"), end_form (); }

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: No results from script
by edoc (Chaplain) on Jun 04, 2003 at 16:21 UTC
    sub get_customer { my ($customer_id) = @_; my $dbh = WebDB::connect (); my $sth = $dbh->prepare ("SELECT * FROM Shipments WHERE customer_id + = ?"); $sth->execute($customer_id); my @customer; ### <-- this was missing while (my $track_ref = $sth->fetchrow_hashref ()){ push(@customer, $track_ref); } return(\@customer); }

    first line of print_results should be:

    sub print_results { my ($customer) = @_; print table ({-border => 0},

    $customer was being assigned with the number of elements in @_...

    cheers,

    J

      Hello, :)

      The help you gave me earlier was awesome. The script works wonderfully. I have one quick and hopefully easy question for you.

      Shouldn't my table data line up underneath my table headings?

      My data shifts back and forth from one row to the next. I pasted the code that creates the table. Any ideas on this would be great?

      Here it is...
      print table ({-border => 0}, Tr ({-align => "CENTER", -valign=>"TOP", -BGCOLOR=>"silver", -st +yle=>"font-family: verdana; font-size: 10pt;"}, th ({-width=>"50"},("Customer ID")), th ({-width=>"50"},("Customer Order")), th ({-width=>"50"},("Purchase Order")), th ({-width=>"90"},("Ship Date")), th ({-width=>"40"},("Carrier")), th ({-width=>"150"},("Tracking Number")), th ({-width=>"60"},("Item Number")), th ({-width=>"50"},("Wt")), th ({-width=>"50"},("Invoice Number")), th ({-width=>"20"},("Qty")), th ({-width=>"50"},("Customer Item Number")) + )); foreach my $row (@$customer) { print table ({-border => 0}, Tr ({-align=>"center", -valign=>"TOP", -style=>"font-family: verda +na; font-size: 10pt;"}, td ({-width=>"60", -align => "center"},(escapeHTML ($row-> +{customer_id}))), td ({-width=>"70", -align => "center"},(escapeHTML ($row-> +{customer_order}))), td ({-width=>"80", -align => "center"},(escapeHTML ($row->{pur +chase_order}))), td ({-width=>"90", -align => "center"},(escapeHTML ($row-> +{ship_date}))), td ({-width=>"40", -align => "center"},(escapeHTML ($row-> +{carrier_id}))), td ({-width=>"175", -align => "center"},(escapeHTML ($row- +>{tracking_number}))), td ({-width=>"45", -align => "center"},(escapeHTML ($row-> +{item_number}))), td ({-width=>"50", -align => "center"},(escapeHTML ($row-> +{weight}))), td ({-width=>"50", -align => "center"},(escapeHTML ($row-> +{invoice_number}))), td ({-width=>"20", -align => "center"},(escapeHTML ($row-> +{quantity_shipped}))), td ({-width=>"50", -align => "center"},(escapeHTML ($row-> +{customer_item_number}))) ));

        Pretty sure that's the CGI stuff, which I've never used. If you look in your html I'd guess you've got a table for the header and a separate table for each row. We should be able to drop 'table ...' from the print in the loop and just print the Tr, but I don't know how to prevent CGI from ending the table when we print the header.

        cheers,

        J

        ok, from another discussion where I got told off for telling fibs..8)

        #!/usr/bin/perl -w use strict; use CGI qw/:standard *table/; print header(), start_html('foo bar qux'), start_table(); print Tr( td('foo'), td('bar'), td('qux') ); print end_table(), end_html();

        so some changes..

        change: use CGI; to: use CGI qw/:standard *table/; change the first: print table ({-border => 0}, to print start_table ({-border => 0}, change in the loop: print table ({-border => 0}, Tr ({-align=>"center", -valign=>"TOP", -style=>"font-family: verda to: print Tr ({-align=>"center", -valign=>"TOP", -style=>"font-family: ver +da and add: print end_table(), after the loop.

        cheers,

        J