Link to home
Start Free TrialLog in
Avatar of Gary040897
Gary040897

asked on

Matt's WebShop part 1

I'm working with Matt's WebShop.cgi from the Perl Cookbook. I have four issues that I need to address. Each issue is posted as a separate question. The script is to long to post here. Working examples of what I have and the issues can be found at http://www.fishhead.com/webshop.html. There is also a link to the scripts at this page. Even though the script is long it is well commented as to each section.

The script uses data files to produce the html with product information such as a description, price and shipping cost. The original script takes you to a generated html page that has more links to the actual products. I would like to eliminate the extra link step and have all the information about the products be displayed when you first open the WebShop. Examples of what I would like are also at http://www.fishhead.com/webshop.html.
Avatar of Gary040897
Gary040897

ASKER

Edited text of question.
Have you tried tried flushing the cache?  You would have to do somehting like
$| = 1;
at the beginning of the script, that way the print statement is written immediately, not cached for later writing.  With CGI you don't want to cache anything.
I haven't tried that. Would I use that as a separate line in the very beginning of the script?
Yes, something like

#!/usr/bin/perl

use strict;

$|=1;

The truth is you can put it anywhere, I just prefer to do it before I open any files for read or write.
That gave me an Internal Server Error.
What version of Perl are you using, and on what OS?
I forgot how to get the version number. I know it's 5.x on UNIX.
That gave me an Internal Server Error.
When you first click the link from the starting page, the 'command' parameter is not defined. This takes you to the 'else' part of the if statement where you check the value of $FORM{'command'} (lines 511 to 518). You need to add the call to the subrotine get_product_info before the call to webshop_parse, like this:

##########################################################
# Otherwise, no specific valid command, send out main intro page.          #
##########################################################

else {
    &update_expire_time;

    # Get Product Info.
    &get_product_info;

    &webshop_parse($INTRO_HTML, 'open->intro_html', *STDOUT);
}
I still get "Internal Server Error". Some of the errors from the log are:

Global symbol "TAXES" requires explicit package name at
/export/home4/gold/e/et/html/cgi-bin/WebShop.cgi line 858.
Global symbol "line" requires explicit package name at
/export/home4/gold/e/et/html/cgi-bin/WebShop.cgi line 861.
Variable "@TAXES" is not imported at /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi line
861.
> Global symbol "TAXES" requires explicit package name at
> /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi line 858.

Make @TAXES 'my' variable.

my @TAXES = <TAXES>;

> Global symbol "line" requires explicit package name at
> /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi line 861

Make $line 'my' variable.

foreach my $line (@TAXES) {

Sorry, I think that error message may have come from help I'm getting from another part of this question.

When I implement everything you had to this point I get Internal Server Error. The error log from just your changes where:

Bareword found where operator expected at /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi
line 1099, near "print "make"
(Do you need to predeclare print?)
String found where operator expected at /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi line
1101, near "print "" 
(Might be a runaway multi-line "" string starting on line 1099)
(Missing semicolon on previous line?)
Bareword found where operator expected at /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi
line 1101, near "/body> (Missing operator before html?)
String found where operator expected at /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi line
1104, near "&error_header(""
(Might be a runaway multi-line "" string starting on line 1101)
(Missing semicolon on previous line?)
Bareword found where operator expected at /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi
line 1104, near "&error_header("WebShop"
(Missing operator before WebShop?)
String found where operator expected at /export/home4/gold/e/et/html/cgi-bin/WebShop.cgi line
1105, near "print "" 
These errors most likely a missing matching quote or bracket. Or may be a missing semi-colon somewhere. Please check the code in that area carefully for these.
For prakashk:

Earlier I had combined your suggestion with olthoff's suggestion. I tried just yours and the page loads without errors but the prices still don't appear until click on the "Return to Exotic Tropicals purchase page" which has the script reload that page and hits the "products.txt" again and picks up the price.
When you first call the script WebShop.cgi it goes to the config.txt The config.txt tells WebShop.cgi that the first page to present is the "INTRO" page with $INTRO_HTML = '/export/home4/gold/e/et/webshop/products.html';. The products.html page is generated by Webshop.cgi based on the page called "products.html" which is different than the one you see in the browser as "products.html". The "products.html" that the script sees has links to "products.txt" which has all the information as to product id, the cost of the product and shipping cost. For some reason all of the product information is not being gathered the first time the script looks at products.txt. You can see in your browser that when you click on the "Return to Exotic Tropicals purchase page" at the bottom of the first page you see when you enter the WebShop, that a unique user id number is established and then the prices appear. I'm trying to accomplish all of that when the initial page loads.
At the end of the subroutine new_user, before the call to webshop_parse, add a call to get_product_info. The resulting code should look like this:

sub new_user {

.... .....

    # Parse Intro HTML Template and send it out.

    &get_product_info;
    &webshop_parse($INTRO_HTML, 'open->intro_html', *STDOUT);

    exit;
}


For prakashk:

With your last comment added everything appears to work as far as question 1 is concerned. I'm assuming you intended for both of your comments to be incorporated in the script modifications. I have a copy of the script as it is now with your changes at http://www.fishhead.com/scripts/question_1/WebShop-cgi.txt. At this point I would say to post both of your changes as a proposed answer so we can close this one out.
Avatar of ozo

ASKER CERTIFIED SOLUTION
Avatar of prakashk021799
prakashk021799

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial