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.
Gary040897Asked:
Who is Participating?
 
prakashk021799Connect With a Mentor Commented:
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);
}

Also, 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;
}
0
 
Gary040897Author Commented:
Edited text of question.
0
 
olthoffCommented:
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.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Gary040897Author Commented:
I haven't tried that. Would I use that as a separate line in the very beginning of the script?
0
 
olthoffCommented:
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.
0
 
Gary040897Author Commented:
That gave me an Internal Server Error.
0
 
olthoffCommented:
What version of Perl are you using, and on what OS?
0
 
Gary040897Author Commented:
I forgot how to get the version number. I know it's 5.x on UNIX.
0
 
Gary040897Author Commented:
That gave me an Internal Server Error.
0
 
prakashk021799Commented:
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);
}
0
 
Gary040897Author Commented:
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.
0
 
prakashk021799Commented:
> 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) {

0
 
Gary040897Author Commented:
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 "" 
0
 
prakashk021799Commented:
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.
0
 
Gary040897Author Commented:
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.
0
 
Gary040897Author Commented:
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.
0
 
prakashk021799Commented:
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;
}


0
 
Gary040897Author Commented:
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.
0
 
ozoCommented:

0
All Courses

From novice to tech pro — start learning today.