473,420 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,420 software developers and data experts.

Bizar variable problem

I have a simple html form that sends 3 values to perl cgi script. The
perl script then makes some calculations and prints the results to the
browser. It also writes the values to a file with some other static
text. Problem is that the values don't get saved to the file. The file
is created and the static text shows up in the file on both sides of
where the values should be, if I print the variables to the browser it
shows them correctly. Now for the bizarre part, if I do this in an old
version of netscape (4.7) then it works fine but any other browser I
have tried (IE, Netscape 7.1, Opera) it gives me this problem, which is
really strange since I can't see how the browser has any effect on the
server side of things. I have tried the script on both MS IIS and
Apache with the same result.
--
Chris W
Jul 19 '05 #1
17 2722
Chris W wrote:
... It also writes the values to a file with some other static
text. Problem is that the values don't get saved to the file.
<snip>
Now for the bizarre part, if I do this in an old version of
netscape (4.7) then it works fine but any other browser I have
tried (IE, Netscape 7.1, Opera) it gives me this problem, which is
really strange since I can't see how the browser has any effect on
the server side of things.


How about posting the script or, even better, a short version of it
that illustrates the problem you describe.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2
Ok here is the code.

#!c:\perl\bin\perl.exe
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;
require 'config.pl';

##############################
###Variables in question######
$item = param("item");
$qty = param("qty");
$price = param("price");
##############################

$cartFileName = CGI::cookie("CartFile");
$total = $qty * $price;
$shipping = "\$3.00";
$gtotalstr = sprintf "%9.2f", ($total + 3 + ($total * $tax));
$taxstr = sprintf "%9.2f", ($total * $tax);
$totalstr = sprintf "%9.2f", $total;

################################################## ################
#########I have moved this code to various places and still no joy
################################################## ################
open CARTFILE, ">$orderdir/$cartFileName";
print CARTFILE "$item - $qty - \$$price\n"; #THIS IS WHAT DOESN'T
WORK.
######the two "-"s and the "$" are all that's in the file.
close CARTFILE;

print CGI::header();
open TEMPLET, "<$cgidir/cart.html";
while(<TEMPLET>){
print;
if(/BODY GOES HERE/){

##########################################
#######This all prints as expected########
print "<br><br>$item - $qty - \$$price\n<BR><BR>";

print <<"[END]";

Sub Total:\$$totalstr<br>
Tax :\$$taxstr<br>
Shipping :$shipping<br>
Total :\$$gtotalstr<br>
<FORM ACTION="$hcgidir/GetPayment.pl" METHOD=POST>
<INPUT TYPE="HIDDEN" NAME="total" VALUE="$total">
Please select payment method.<br>
<input type="radio" name="paymentType" value="CreditCard">Credit
Card
<input type="radio" name="paymentType" value="Check">Mail Check
<INPUT TYPE="submit" name="submit" value="Continue">
</FORM>
<br>
</form>

[END]

}#end if
} #end while templet

--
Chris W
Jul 19 '05 #3
Chris W wrote:
Ok here is the code.

#!c:\perl\bin\perl.exe
use strict;
use warnings;

<snip>
open CARTFILE, ">$orderdir/$cartFileName";
print CARTFILE "$item - $qty - \$$price\n"; #THIS IS WHAT DOESN'T WORK.


open CARTFILE, ">$orderdir/$cartFileName" or die $!;

The above suggestions are the basic methods to ask Perl for help with
finding various code errors. Please use those methods before asking a
Usenet group to help you debug your code.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #4
Gunnar Hjalmarsson wrote:
#!c:\perl\bin\perl.exe
use strict;
use warnings;


No change in behavior of the code once all the strict stuff was added.
The only warnings were about a few vars from config.pl that are only
used once and that isn't part of the problem


open CARTFILE, ">$orderdir/$cartFileName" or die $!;


I took my long or die thing out to simplify and that obviously isn't the
problem, since as I said in my first message, the file is being created
and written to, it just doesn't write the value of my variables in the
file.

Chris W
Jul 19 '05 #5
Chris W wrote:
Gunnar Hjalmarsson wrote:

open CARTFILE, ">$orderdir/$cartFileName" or die $!;
I took my long or die thing out to simplify


I suggest that you take it back. You should make it a habit to never
"simplify" that way, btw.
and that obviously isn't the problem,
That's not obvious to me.
since as I said in my first message, the file is being created and
written to, it just doesn't write the value of my variables in the
file.


If the variables are populated (which they obviously are if their
content is printed to the screen), I find it very hard to believe that
the script would actually print to the file and still exclude the
variables. Maybe there is just an old file copy, and nothing gets
printed. Maybe, since the filename seems to be dependent on some
cookie, there is a cookie problem... You would get a clue if you
checked the return value of that open statement.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #6
Gunnar Hjalmarsson wrote:
If the variables are populated (which they obviously are if their
content is printed to the screen), I find it very hard to believe that
the script would actually print to the file and still exclude the
variables.
I find it hard to believe too, that's why I have tested it a million
times and, that is exactly what happens if I use any browser except
Netscape 4.7
Maybe there is just an old file copy, and nothing gets
printed.
The file name is based on the time of day and every time I run the
script it creates a new file I now have about 50 files with a first line
that looks like "$ - -", so I know that's not the problem. Another
script down the road also has not problem adding other data to the file,
which makes it even more difficult to believe.
Maybe, since the filename seems to be dependent on some
cookie, there is a cookie problem... You would get a clue if you
checked the return value of that open statement.


adding to or die in there doesn't change anything.
I Just did some experimenting and noticed something odd. . . if I change

open CARTFILE, ">$conf::orderdir/$cartFileName" or die $!;
#the file should already exist at this point

to

open CARTFILE, ">>$conf::orderdir/$cartFileName" or die $!;

Then the first line of the file is exactly like I want it to be, but it
also prints a second line that doesn't have any values, just the " - -
$"

So what does that tell you?

--
Chris W
Jul 19 '05 #7
Chris W wrote:
I Just did some experimenting and noticed something odd. . . if I change

open CARTFILE, ">$conf::orderdir/$cartFileName" or die $!;
#the file should already exist at this point

to

open CARTFILE, ">>$conf::orderdir/$cartFileName" or die $!;

Then the first line of the file is exactly like I want it to be, but it
also prints a second line that doesn't have any values, just the " - -
$"


I forgot to mention that again it works in netscape 4.7 as I expect it
to, it is only when I use any other browser that it has the problem.

Chris W
Jul 19 '05 #8
Chris W wrote:
Gunnar Hjalmarsson wrote:
Maybe, since the filename seems to be dependent on some cookie,
there is a cookie problem... You would get a clue if you checked
the return value of that open statement.


adding to or die in there doesn't change anything.

I Just did some experimenting and noticed something odd. . . if I
change

open CARTFILE, ">$conf::orderdir/$cartFileName" or die $!;
#the file should already exist at this point

to

open CARTFILE, ">>$conf::orderdir/$cartFileName" or die $!;

Then the first line of the file is exactly like I want it to be,
but it also prints a second line that doesn't have any values, just
the " - - $"

So what does that tell you?


Not much. What happens if you hardcode the file name instead of
relying on the cookie value?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #9
Gunnar Hjalmarsson wrote:
Not much. What happens if you hardcode the file name instead of
relying on the cookie value?


Same thing. I decied to look in my access long and found these
interesting entries.

When I run the script from IE or Opera or Netscape 7.1 I get this. . .

"POST /cgi-bin/addToCart.pl HTTP/1.1" 200 6473
"GET /cgi-bin/addToCart.pl? HTTP/1.1" 200 6417

When I use netscape 4.7 I get this in the long

"POST /cgi-bin/addToCart.pl HTTP/1.0" 200 6521
"GET /cgi-bin/? HTTP/1.0" 403 286

That has to have something to do with it

--
Chris W
Jul 19 '05 #10
Instead of

print CARTFILE "...";

You should try

printf CARFILE "....";

printf prints content to a file.

"Chris W" <ch*****@cox.net> wrote in message
news:3F**************@cox.net...
Ok here is the code.

#!c:\perl\bin\perl.exe
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;
require 'config.pl';

##############################
###Variables in question######
$item = param("item");
$qty = param("qty");
$price = param("price");
##############################

$cartFileName = CGI::cookie("CartFile");
$total = $qty * $price;
$shipping = "\$3.00";
$gtotalstr = sprintf "%9.2f", ($total + 3 + ($total * $tax));
$taxstr = sprintf "%9.2f", ($total * $tax);
$totalstr = sprintf "%9.2f", $total;

################################################## ################
#########I have moved this code to various places and still no joy
################################################## ################
open CARTFILE, ">$orderdir/$cartFileName";
print CARTFILE "$item - $qty - \$$price\n"; #THIS IS WHAT DOESN'T
WORK.
######the two "-"s and the "$" are all that's in the file.
close CARTFILE;

print CGI::header();
open TEMPLET, "<$cgidir/cart.html";
while(<TEMPLET>){
print;
if(/BODY GOES HERE/){

##########################################
#######This all prints as expected########
print "<br><br>$item - $qty - \$$price\n<BR><BR>";

print <<"[END]";

Sub Total:\$$totalstr<br>
Tax :\$$taxstr<br>
Shipping :$shipping<br>
Total :\$$gtotalstr<br>
<FORM ACTION="$hcgidir/GetPayment.pl" METHOD=POST>
<INPUT TYPE="HIDDEN" NAME="total" VALUE="$total">
Please select payment method.<br>
<input type="radio" name="paymentType" value="CreditCard">Credit
Card
<input type="radio" name="paymentType" value="Check">Mail Check
<INPUT TYPE="submit" name="submit" value="Continue">
</FORM>
<br>
</form>

[END]

}#end if
} #end while templet

--
Chris W

Jul 19 '05 #11
Alex Zeng wrote:
Instead of

print CARTFILE "...";

You should try

printf CARFILE "....";
Why do you think a formatted print without a format would solve any problem?
printf prints content to a file.


True. Just as print() does.
Actually neither print nor printf care much about where CARFILE is pointing
to. It could be a file, could be printer, could be a port, could be a
monitor, could be anything else.

jue
Jul 19 '05 #12
My Bad, I got confused with C/Perl. In C, printf is used to print to file
Jul 19 '05 #13
I saw the script was running on Windows platform, could that be because of
the pathname of a file is different from Linux? Like

$order_dir/$cart_file_name

shall really be:

$order_dir\\$cart_file_name ???

Print out the filename, and see if it follows the MS Window file naming
convention.

"Chris W" <ch*****@cox.net> wrote in message
news:3F**************@cox.net...
Ok here is the code.

#!c:\perl\bin\perl.exe
use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;
require 'config.pl';

##############################
###Variables in question######
$item = param("item");
$qty = param("qty");
$price = param("price");
##############################

$cartFileName = CGI::cookie("CartFile");
$total = $qty * $price;
$shipping = "\$3.00";
$gtotalstr = sprintf "%9.2f", ($total + 3 + ($total * $tax));
$taxstr = sprintf "%9.2f", ($total * $tax);
$totalstr = sprintf "%9.2f", $total;

################################################## ################
#########I have moved this code to various places and still no joy
################################################## ################
open CARTFILE, ">$orderdir/$cartFileName";
print CARTFILE "$item - $qty - \$$price\n"; #THIS IS WHAT DOESN'T
WORK.
######the two "-"s and the "$" are all that's in the file.
close CARTFILE;

print CGI::header();
open TEMPLET, "<$cgidir/cart.html";
while(<TEMPLET>){
print;
if(/BODY GOES HERE/){

##########################################
#######This all prints as expected########
print "<br><br>$item - $qty - \$$price\n<BR><BR>";

print <<"[END]";

Sub Total:\$$totalstr<br>
Tax :\$$taxstr<br>
Shipping :$shipping<br>
Total :\$$gtotalstr<br>
<FORM ACTION="$hcgidir/GetPayment.pl" METHOD=POST>
<INPUT TYPE="HIDDEN" NAME="total" VALUE="$total">
Please select payment method.<br>
<input type="radio" name="paymentType" value="CreditCard">Credit
Card
<input type="radio" name="paymentType" value="Check">Mail Check
<INPUT TYPE="submit" name="submit" value="Continue">
</FORM>
<br>
</form>

[END]

}#end if
} #end while templet

--
Chris W

Jul 19 '05 #14
Alex Zeng wrote:
I saw the script was running on Windows platform, could that be
because of the pathname of a file is different from Linux? Like

$order_dir/$cart_file_name

shall really be:

$order_dir\\$cart_file_name ???

Print out the filename, and see if it follows the MS Window file
naming convention.


There is no such need. '/' can well (and should better) be used as the
directory separator when writing paths in Perl, whether the program
shall be run on Unix/Linux or Windows.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #15
I figured it out last night. I started thinking about the templet file
my script was reading and printing around it's dynamic output. There is
a lot of java script in there and I was wondering if that was making it
reload, so I commented out the parts that read in the templet with all
the java script and low and behold problem solved :) Now all I need to
do is figure out why the java script is making my script reload and how
to stop it.

Here is a link to just the templet file with out any of the dynamic data
from the script in case anyone cares to look at java script.

http://cdw.homelinux.com:8086/Cart.html

--
Chris W

"They that can give up essential liberty
to obtain a little temporary safety
deserve neither liberty nor safety."
-- Benjamin Franklin, 1759 Historical Review of Pennsylvania
Jul 19 '05 #16
Chris W wrote:

I figured it out last night. I started thinking about the templet file
my script was reading and printing around it's dynamic output. There is
a lot of java script in there and I was wondering if that was making it
reload, so I commented out the parts that read in the templet with all
the java script and low and behold problem solved :) Now all I need to
do is figure out why the java script is making my script reload and how
to stop it.

Here is a link to just the templet file with out any of the dynamic data
from the script in case anyone cares to look at java script.

http://cdw.homelinux.com:8086/Cart.html

got this reply on a java script ng and it fixed the problem
This line:
<body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#106BA5" VLINK="#A56B10"
ALINK="#FF00FF" BACKGROUND="?">

Is trying to load a background image named "?".
That's what's causing that second hit.

Thanks for everyone's help in trouble shooting and giving me other ideas
for improvement.
--
Chris W

"They that can give up essential liberty
to obtain a little temporary safety
deserve neither liberty nor safety."
-- Benjamin Franklin, 1759 Historical Review of Pennsylvania
Jul 19 '05 #17
This line:
<body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#106BA5" VLINK="#A56B10"
ALINK="#FF00FF" BACKGROUND="?">

Is trying to load a background image named "?".
That's what's causing that second hit.

Thanks for everyone's help in trouble shooting and giving me other ideas
for improvement.


Wow! A "?" caused all the problems!!!! Uggh
Jul 19 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
5
by: William of Ockham | last post by:
Hi, I was asked to recreate a new clean database for our developers because the current one they use is not entirely up to date. So I created a new database and I run into the followin strange...
9
by: Pyenos | last post by:
Approach 1: class Class1: class Class2: def __init__(self):self.variable="variable" class Class3: def method():print Class1().Class2().variable #problem Approach 1.1:
2
by: =?Utf-8?B?VkxOTA==?= | last post by:
Hi all, I have got a really weird problem: - A normal VB.net forms application - One MDI child form with a bunch of controls (tabs, radiobuttons, combo's, etc.) - The form is called from...
0
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
10
by: Mason Barge | last post by:
I have a standard POST form consisting of two types of input: text input and textarea. The form downloads current settings from a mysql database. The user can update the information by modifying...
1
NeoPa
by: NeoPa | last post by:
Problem Description : In VBA there is an option to enforce declaration of variables in your code. With this set, any reference to a variable that has not been previously declared (Dim; Private;...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.