Checklist for Assignment 3
I have received a large number of emails essentially asking the same kind
of questions. Instead of answering each of them individually, I am posting
my answers here.
DBD::CSV
Most problems concern access to the database. Many of you report that they
can access the database when accessing their CGI script from the command
line, but not when executing it through CGI. They then blame an apparent
error in the DBD::CSV installation. Nothing further from the truth. Here
is a list of things you should check for in your set-up. BTW- running the
script from the command line can even be the source of the error!
-
Make sure that the directory (fdir) where the database should be created
exists, and is writable. DBD::CSV will not create the directory for you.
-
Make sure that the permissions on the directory are set such that a CGI
script can write to it. Remember that a CGI script runs as a different
user from you, most often as user nobody. You need to give that user write
access to the database, which you can do by setting permissions to 777
for the database directory. Also make sure any directory containing this
directory has permssions 711 set.
-
Make sure that the permissions on the file that stores the "cart" table
(e.g. "cart") in the database directory are set such that a CGI script
can write to it. By running the CGI script from the command line, you may
actually set the permissions to read-only for other users than yourself.
Reset them to 777.
Another common problem is caused by using the wrong method to submit a
form:
-
If you use GET, the contents of the resulting page may be cached by your
browser, and you won't see any of the changes that you have made to your
database. Using POST tells the browser that the contents of the page should
always be updated when the CGI script is executed.
Other problems are caused by not making good use of the facilities of Perl:
-
Make sure that you use CGI::Carp( fatalsToBrowser ). Then you will actually
see an error message instead of an "Internal Server Error". Only then
will the TAs (or we) be able to help you.
To repeat, none of these problems are caused by the DBD::CSV module.
Cookies
Some of you reported problems with setting a cookie for the user id, when
using the cookie() method in the CGI.pm. Kindly refer to pages 287/8 in
the book for a detailed description of how to use it.
The key to understanding the example in the book is that cookies are
part of the header sent with the HTTP response. That is, you must set a
cookie in the header() method, as follows:
$cookie = $q->cookie(-name => "name", -value => "value", -expires
=> "+1h");
print $q->header(-type => "text/html", -cookie => $cookie);
Sigma10
Some people reported problems with accessing sigma10. I have only noticed
intermittent problems, probably due to high load. The server generally
comes back to operation shortly after.
However, your request might still "hang" in the browser. You will have
to resubmit the request. I would suggest to "ping" the web server, when
you encounter such problems, and test if it is back online: ping sigma10.
Requirements
Now to the questions of which I would have expected a lot more.
-
How is the quantity field used? Given the wording of the assignment, the
quantity can only be 1. It would be a rather straightforward extension
to add an input field for the quantity, but we wanted to minimize the changes
required to the templates from assignment 2. A real shopping cart, of course,
may have quantities > 1, which is why this info is in the database schema.
-
In question 4 you ask us to redirect the browser to the Shop205DisplayCategories.cgi
script. Does that mean that I cannot pick new categories, once I have entered
items into the shopping cart? Yes, it does. Again, this is a simplification,
mainly to keep the assignment small. While a capability to browse a product
catalog and add items to the shopping cart, as we browse it, would definitely
be nice to have, this would require you to write significant extra code,
and make the database schema more complex.
-
One requirement, however, became redundant after the changes to simplify
the assignment (and I apologize for that), is the "Show Shopping Cart"
button. Since a cookie is created for the user, once they saved their shopping
cart, the user cannot return to the home page, where they can select to
see the shopping cart. Case 2 of question 2 therefore usually gets executed
as a result of redirection (question 4).
-
Note also that we ask you to save the shopping cart only when the
user says so. The contents will not be saved automatically every time the
user makes a change to the cart.