b310 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have a database that contains shipment information. Right now, I want to show two fields: customer_id and tracking_number.

I have an HTML form where the customer will enter their customer id number. The form element name is custid.

I'm trying to write a script that will take the customer id number which was entered into the form and passed to the database table to extract the information only for that customer.

When I run the script, I'm receiving a compilation error and I'm not sure what the problem could be.

Below is the code for the script.

Any help is greatly appreciated.

Thank you in advance.
#!/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 escape escapeHTML); use WebDB; my $cust_ref; #reference to customer #@PAGE_START my $dbh = WebDB::connect (); my $page = h3 ({-align=>"center"}, ("Order Tracking System")); #@PAGE_START # get the form parameters $cust_ref->{custid} = param ("custid"); my $choice = lc (param ("choice")); if ($choice eq "submit") # customer submitted ID number { $page .= get_customer ($dbh, $cust_ref); } else { $page .= p (escapeHTML ("Logic error, unknown choice: $choice")); } print header (), start_html (-title => "Order Tracking System", -bgcol +or => "white"); sub get_customer { my ($dbh, $cust_ref) = @_; my ($page); my $sth = $dbh->prepare ("SELECT * FROM Shipments WHERE customer_id = +?"); $sth->execute ($cust_ref->{custid}); my @rows; while (my $order_ref = $sth->fetchrow_hashref ()) { push @rows, Tr ({-style=>"font-family: verdana; font-size: 10pt;"}, td ({-colspan => "2"}, ""), td ({-colspan => "3", -align=>"right", -style=>"font-weight: +700;"}, "Customer ID:"), td (escapeHTML ($order_ref->{customer_id)), ); Tr ({-style=>"font-family: verdana; font-size: 10pt;"}, td ({-colspan => "2"}, ""), td ({-colspan => "3", -align=>"right", -style=>"font-weight: +700;"}, "Tracking Number:"), td (escapeHTML ($order_ref->{tracking_number)), ); $page .= table ({-border => 1, -align => "center"}, return ($page); $sth->finish(); }

Replies are listed 'Best First'.
Re: Compilation Error
by vek (Prior) on Jun 02, 2003 at 16:57 UTC
    Looks like you're missing a couple of right curly brackets with your $order_ref hash ref:
    td (escapeHTML ($order_ref->{customer_id)),
    Should be:
    td (escapeHTML ($order_ref->{customer_id})),
    And here also:
    td (escapeHTML ($order_ref->{tracking_number)),
    Should be:
    td (escapeHTML ($order_ref->{tracking_number})),
    See if that does the trick.

    -- vek --
      Hi,

      I included the missing curly brackets and that did not help the situation. Unfortunately, I am unable to get to the logs to find out what is the exact error.
        Hmm, looks like you'll need to fix this line also:
        $page .= table ({-border => 1, -align => "center"},
        Should probably be (untested):
        $page .= table ({-border => 1, -align => "center"});
        Remember, perl -c is your friend and will point out these types of errors.

        -- vek --
Re: Compilation Error
by shemp (Deacon) on Jun 02, 2003 at 16:47 UTC
    It would be helpful if you included the error itself in your post. You can dig it out of the error logs of whatever web server you're using, or, if its actually an interpreter (syntax) error, just capture the output of
    perl -c scriptname
Re: Compilation Error
by WhiteBird (Hermit) on Jun 03, 2003 at 00:18 UTC
    Vek kindly pointed out some of the errors in the code. I just wanted to add a general reminder that compilation errors generally remind me to go back and go over my code with a very close eye on the syntax that might be altered by typing errors and carelessness. I count the parans and the curly braces, check the semi-colons, the double and single quotes, etc. and make sure that everything is correct. I've learned that attention to detail can save me hours of frustration. Good luck sorting it out.
    WB