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

cool.. In get_customer() your customer id is being put into $dbh. As you assign directly to $dbh you don't need it in that first line, so..

change: sub get_customer { my ($dbh, $customer_id) = @_; $dbh = WebDB::connect (); ... to: sub get_customer { my ($customer_id) = @_; my $dbh = WebDB::connect ();

Now you really want to keep the subs separate, so instead of calling get_customer from print_results we get_customer, then send the customer details to print results..

if ($choice eq "submit") # customer submitted order number { get_customer (); print_results (); } else ... becomes: if ($choice eq "submit") # customer submitted order number { my $cutomer = get_customer($customer_id); print_results($customer); } else ...

Then we change print_results to accept the customer details as an argument

sub print_results { my $customer = get_customer($customer_id); ... becomes: sub print_results { my $customer = @_;

cheers,

J

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: No results from script
by b310 (Scribe) on Jun 04, 2003 at 16:12 UTC
    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 (); }
      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}))) ));