Still Having Problems Writing To The CSV File...

Problems installing or using the NOP Design Free Shopping Cart. **ARCHIVE** Please post new topics to one of the groups below.

Moderator: scott

Still Having Problems Writing To The CSV File...

Postby Simon Lane » Tue Mar 04, 2003 12:44 pm

Hi everyone

I have sorted most of the problems I have had with the script ( thanks to everyone who helped ) and now receive an email and send one to the customer...

Two problems though...

The information still isn't being written to the CSV. I have changed permissions to 755 but still do not have the information stored in the csv. I need some help with this please as I do not want to email credit card details across the net.

Also my header and footer do not appear on the final confirmation page - is this because the rest of the site doesn't use frames ? Could I just make a last page from scratch to be called after the customers information is submitted instead of using the write to page method ?

Thanks again for all your help...

Simon
Simon Lane
 
Posts: 30
Joined: Wed Feb 05, 2003 1:18 pm
Location: UK

Postby justin » Tue Mar 04, 2003 1:55 pm

Show us a copy of your checkout.pl, see if we can spot an overlooked mistake.

Are the header and footer pages in your cgi-bin?

Yes you can call a thankyou page. Create a thankyou.htm page to your requirements and replace the code in your checkout.pl.

Like this:
add this line to the variables at the top of the page, same as $header, $footer.

$thankyou = "thankyou.htm";

Change the code at the bottom of the checkout.pl to this.

print "Content-type: text/html\n\n";

open (HEAD, $thankyou);
@LINES = <HEAD>;
close HEAD;
print @LINES;

exit;


Put the thankyou.htm in your cgi-bin.
justin
 
Posts: 53
Joined: Fri Nov 29, 2002 4:35 pm
Location: UK

Justin...

Postby Simon Lane » Tue Mar 04, 2003 3:50 pm

#!/usr/bin/perl
#=====================================================================||
# NOP Design JavaScript Shopping Cart ||
# PERL CGI Checkout Module ||
#=====================================================================||
require 5.001;

########################################################################
# #
# User defined variables: #
# $header - string value containing the complete #
# path of the HTML page header #
# $footer - string value containing the complete #
# path of the HTML page footer #
# $mailprogram - string value containing the complete path to #
# the sendmail binary on the system. #
# $youremail - string value containing the email address to #
# send catalog orders in EMAIL or BOTH modes #
# **Don't forget to put a \ before the @ in your #
# email address. ie. spam\@nopdesign.com*** #
# $returnpage - URL to send user when checkout is complete #
# $csvfilename - string value containing the complete #
# path of the user database. #
# $csvquote - string value containing what to use for quotes #
# in the csv file (typically "" or \") #
# $mode - string value containing 'EMAIL', 'FILE' or #
# 'BOTH' to determine if the script should send #
# an email to you with the new order, write the #
# order to a CSV file, or do both. #
########################################################################
$mailprogram = "/usr/sbin/sendmail -t";
$returnpage = "http://www.h-e-l.co.uk/English/index.htm";
$youremail = "onlineorder\@h-e-l.co.uk";
$csvfilename = "http://www.h-e-l.co.uk/cgi-bin/orders.csv";
$csvquote = "\"\"";
$mode = "BOTH";
$footer = "http://www.h-e-l.co.uk/cgi-bin/footer.html";
$header = "http://www.h-e-l.co.uk/cgi-bin/header.html";


#These are required fields. I recommend enforcing these by javascript,
#but let's just make sure here as well.
@required = (
'b_first',
'b_last',
'b_addr',
'b_city',
'b_state',
'b_zip',
'b_phone',
'b_email'
);

##############################################################
#FUNCTION: urlDecode #
#RETURNS: The decoded string. #
#PARAMETERS: An encoded string. #
#PURPOSE: Decodes a URL encoded string. #
##############################################################
sub urlDecode {
my ($string) = @_;
$string =~ tr/+/ /;
$string =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex($1))/eg;
$string =~ s/['"]/\'/g;
return ($string);
}

##############################################################
#FUNCTION: processCGI #
#RETURNS: #
#PARAMETERS: #
#PURPOSE: Retrieves form data submitted via the 'GET' #
# method and decodes it. You may then access #
# the passed in variables via calls to $[name] #
# where [name] is the name of the form element. #
##############################################################
sub processCGI {
local ($cgiData, $key, $value, $pair, @pairs);

if ($ENV{'REQUEST_METHOD'} eq 'GET') { $cgiData = $ENV{'QUERY_STRING'}; }
else { $cgiData = <STDIN>; }
@pairs = split (/&/, $cgiData);
foreach $pair (@pairs) {
($key, $value) = split (/\=/, $pair);
$key = &urlDecode($key);
$value = &urlDecode($value);
if(defined ${$key}){
${$key} .= ", ".$value;
}else{
${$key} = $value;
}
}
}

##############################################################
#FUNCTION: doFormError #
#RETURNS: #
#PARAMETERS: A error message string. #
#PURPOSE: Generates an HTML page indicating a form #
# submission error occurred. #
##############################################################
sub doFormError {
my ($errString) = @_;

open (HEAD, $header);
@LINES = <HEAD>;
close HEAD;

print "Content-type: text/html\n\n";

print @LINES;

print "<FONT SIZE=+2>The form you submitted was not complete.<BR><BR></FONT>";
print "$errString<BR><BR>\n";
print "<INPUT TYPE=BUTTON ONCLICK='history.back()' VALUE=' Return to the checkout page '><HR>";

open (FOOT, $footer);
@LINES = <FOOT>;
close FOOT;
print @LINES;

exit;
}

##############################################################
#FUNCTION: doError #
#RETURNS: #
#PARAMETERS: A error message string. #
#PURPOSE: Generates an HTML page indicating an error #
# occurred. #
##############################################################
sub doError {
my ($errString) = @_;
print "Content-type: text/html\n\n";

open (HEAD, $header);
@LINES = <HEAD>;
close HEAD;

print @LINES;

print "$errString<BR><BR>\n";

open (FOOT, $footer);
@LINES = <FOOT>;
close FOOT;
print @LINES;

exit;
}

##############################################################
#FUNCTION: invalidE #
#RETURNS: 1 if invalid, 0 if valid. #
#PARAMETERS: An email address variable. #
#PURPOSE: Checks to see if a submitted email address is #
# of the valid form 'x@y'. #
##############################################################
sub invalidE {
my ($szEmail) = @_;
my ($user, $host);

$szEmail =~ tr/A-Z/a-z/;
if ($szEmail =~ /\s/) { return 1; }
($user, $host) = split (/\@/, $szEmail);
if ($host =~ /compuserve/i) { ; }
else {
if (! $user =~ /\D/) { return 1; }
if (! $host =~ /\D/) { return 1; }
if (substr ($user,0,1) !~ /[a-z]/) { return 1; }
}
if ($szEmail =~ /\w+\@[\w|\.]/) { return 0; }
else { return 1; }
}


sub populateDateVar {
@months = ();
push(@months,"January");
push(@months,"February");
push(@months,"March");
push(@months,"April");
push(@months,"May");
push(@months,"June");
push(@months,"July");
push(@months,"August");
push(@months,"September");
push(@months,"October");
push(@months,"November");
push(@months,"December");
@days = ();
push(@days,"Sunday");
push(@days,"Monday");
push(@days,"Tuesday");
push(@days,"Wednesday");
push(@days,"Thursday");
push(@days,"Friday");
push(@days,"Saturday");
($sec,$min,$hour,$day,$month,$year,$day2) =
(localtime(time))[0,1,2,3,4,5,6];
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($day < 10) { $day = "0$day"; }
$year += "1900";

#$todaysdate = "$months[$month] $day, $year $hour:$min:$sec";
}


##############################################################
##############################################################
### MAIN ###
##############################################################
##############################################################

# process the form input.
&processCGI;
&populateDateVar;

foreach $check(@required) {
unless ($check) {
doFormError("It appears that you forgot to fill in the <strong>$check</strong> field.");
exit;
}
}

# checks for valid email address
if( &invalidE($b_email) ){
doFormError('You submitted an invalid email address.');
}


if( $mode eq "BOTH" || $mode eq "EMAIL") {
# Send email order to you...
open (MAIL,"|$mailprogram");
print MAIL "To: $youremail\n";
print MAIL "From: $b_email\n";
print MAIL "Subject: HEL Performance Online Order\n";
print MAIL "\n\n";
print MAIL "A new order has been received. A summary of this order appears below.\n";
print MAIL "\n";
print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n";
print MAIL " \n";
print MAIL " $b_first $b_last \n";
print MAIL " $b_addr \n";
print MAIL " $b_addr2 \n";
print MAIL " $b_city, $b_state $b_zip \n";
print MAIL " $b_phone \n";
print MAIL " $b_fax \n";
print MAIL " $b_email \n";
print MAIL " $s_name \n";
print MAIL " $s_provider \n";
print MAIL " $s_cardno \n";
print MAIL " $s_start \n";
print MAIL " $s_finish \n";
print MAIL " $s_comments \n";
print MAIL " \n";
print MAIL " \n";
print MAIL "Qty Price(\$) Product ID - Product Name\n";
print MAIL "===================================================================== \n";
print MAIL "$QUANTITY_1 \$$PRICE_1 $ID_1 - $NAME_1 $ADDTLINFO_1 \n";
if( $NAME_2 ) {print MAIL "$QUANTITY_2 \$$PRICE_2 $ID_2 - $NAME_2 $ADDTLINFO_2 \n";}
if( $NAME_3 ) {print MAIL "$QUANTITY_3 \$$PRICE_3 $ID_3 - $NAME_3 $ADDTLINFO_3 \n";}
if( $NAME_4 ) {print MAIL "$QUANTITY_4 \$$PRICE_4 $ID_4 - $NAME_4 $ADDTLINFO_4 \n";}
if( $NAME_5 ) {print MAIL "$QUANTITY_5 \$$PRICE_5 $ID_5 - $NAME_5 $ADDTLINFO_5 \n";}
if( $NAME_6 ) {print MAIL "$QUANTITY_6 \$$PRICE_6 $ID_6 - $NAME_6 $ADDTLINFO_6 \n";}
if( $NAME_7 ) {print MAIL "$QUANTITY_7 \$$PRICE_7 $ID_7 - $NAME_7 $ADDTLINFO_7 \n";}
if( $NAME_8 ) {print MAIL "$QUANTITY_8 \$$PRICE_8 $ID_8 - $NAME_8 $ADDTLINFO_8 \n";}
if( $NAME_9 ) {print MAIL "$QUANTITY_9 \$$PRICE_9 $ID_9 - $NAME_9 $ADDTLINFO_9 \n";}
if( $NAME_10 ){print MAIL "$QUANTITY_10 \$$PRICE_10 $ID_10 - $NAME_10 $ADDTLINFO_10 \n";}
if( $NAME_11 ){print MAIL "$QUANTITY_11 \$$PRICE_11 $ID_11 - $NAME_11 $ADDTLINFO_11 \n";}
if( $NAME_12 ){print MAIL "$QUANTITY_12 \$$PRICE_12 $ID_12 - $NAME_12 $ADDTLINFO_12 \n";}
if( $NAME_13 ){print MAIL "$QUANTITY_13 \$$PRICE_13 $ID_13 - $NAME_13 $ADDTLINFO_13 \n";}
print MAIL "===================================================================== \n";
print MAIL "SUBTOTAL: $SUBTOTAL \n";
print MAIL "TOTAL: $TOTAL \n";
print MAIL "\n";
print MAIL "FREIGHT: $SHIPPING \n";
print MAIL "\n\n";
print MAIL "Comments: \n";
print MAIL "--------- \n";
print MAIL "$comment \n";
print MAIL " \n";
close MAIL;
}


if( $mode eq "BOTH" || $mode eq "FILE") {

$csvcomments = $comment;
#$csvcomments =~ s/\"/$csvquote/ig;

open (CSVF,">>$csvfilename");
print CSVF "\"";
print CSVF "$months[$month] $day, $year $hour:$min:$sec";
print CSVF "\",\"";
print CSVF "$b_first";
print CSVF "\",\"";
print CSVF "$b_last";
print CSVF "\",\"";
print CSVF "$b_addr";
print CSVF "\",\"";
print CSVF "$b_addr2";
print CSVF "\",\"";
print CSVF "$b_city";
print CSVF "\",\"";
print CSVF "$b_state";
print CSVF "\",\"";
print CSVF "$b_zip";
print CSVF "\",\"";
print CSVF "$b_phone";
print CSVF "\",\"";
print CSVF "$b_fax";
print CSVF "\",\"";
print CSVF "$b_email";
print CSVF "\",\"";
print CSVF "$s_first";
print CSVF "\",\"";
print CSVF "$s_last";
print CSVF "\",\"";
print CSVF "$s_addr";
print CSVF "\",\"";
print CSVF "$s_addr2";
print CSVF "\",\"";
print CSVF "$s_city";
print CSVF "\",\"";
print CSVF "$s_state";
print CSVF "\",\"";
print CSVF "$s_zip";
print CSVF "\",\"";
print CSVF "$s_phone";
print CSVF "\",\"";
print CSVF "$QUANTITY_1";
print CSVF "\",\"";
print CSVF "\$$PRICE_1";
print CSVF "\",\"";
print CSVF "$ID_1";
print CSVF "\",\"";
print CSVF "$NAME_1";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_1";
print CSVF "\",\"";
print CSVF "$QUANTITY_2";
print CSVF "\",\"";
print CSVF "\$$PRICE_2";
print CSVF "\",\"";
print CSVF "$ID_2";
print CSVF "\",\"";
print CSVF "$NAME_2";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_2";
print CSVF "\",\"";
print CSVF "$QUANTITY_3";
print CSVF "\",\"";
print CSVF "\$$PRICE_3";
print CSVF "\",\"";
print CSVF "$ID_3";
print CSVF "\",\"";
print CSVF "$NAME_3";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_3";
print CSVF "\",\"";
print CSVF "$QUANTITY_4";
print CSVF "\",\"";
print CSVF "\$$PRICE_4";
print CSVF "\",\"";
print CSVF "$ID_4";
print CSVF "\",\"";
print CSVF "$NAME_4";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_4";
print CSVF "\",\"";
print CSVF "$QUANTITY_5";
print CSVF "\",\"";
print CSVF "\$$PRICE_5";
print CSVF "\",\"";
print CSVF "$ID_5";
print CSVF "\",\"";
print CSVF "$NAME_5";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_5";
print CSVF "\",\"";
print CSVF "$QUANTITY_6";
print CSVF "\",\"";
print CSVF "\$$PRICE_6";
print CSVF "\",\"";
print CSVF "$ID_6";
print CSVF "\",\"";
print CSVF "$NAME_6";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_6";
print CSVF "\",\"";
print CSVF "$QUANTITY_7";
print CSVF "\",\"";
print CSVF "\$$PRICE_7";
print CSVF "\",\"";
print CSVF "$ID_7";
print CSVF "\",\"";
print CSVF "$NAME_7";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_7";
print CSVF "\",\"";
print CSVF "$QUANTITY_8";
print CSVF "\",\"";
print CSVF "\$$PRICE_8";
print CSVF "\",\"";
print CSVF "$ID_8";
print CSVF "\",\"";
print CSVF "$NAME_8";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_8";
print CSVF "\",\"";
print CSVF "$QUANTITY_9";
print CSVF "\",\"";
print CSVF "\$$PRICE_9";
print CSVF "\",\"";
print CSVF "$ID_9";
print CSVF "\",\"";
print CSVF "$NAME_9";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_9";
print CSVF "\",\"";
print CSVF "$QUANTITY_10";
print CSVF "\",\"";
print CSVF "\$$PRICE_10";
print CSVF "\",\"";
print CSVF "$ID_10";
print CSVF "\",\"";
print CSVF "$NAME_10";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_10";
print CSVF "\",\"";
print CSVF "$QUANTITY_11";
print CSVF "\",\"";
print CSVF "\$$PRICE_11";
print CSVF "\",\"";
print CSVF "$ID_11";
print CSVF "\",\"";
print CSVF "$NAME_11";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_11";
print CSVF "\",\"";
print CSVF "$QUANTITY_12";
print CSVF "\",\"";
print CSVF "\$$PRICE_12";
print CSVF "\",\"";
print CSVF "$ID_12";
print CSVF "\",\"";
print CSVF "$NAME_12";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_12";
print CSVF "\",\"";
print CSVF "$QUANTITY_13";
print CSVF "\",\"";
print CSVF "\$$PRICE_13";
print CSVF "\",\"";
print CSVF "$ID_13";
print CSVF "\",\"";
print CSVF "$NAME_13";
print CSVF "\",\"";
print CSVF "$ADDTLINFO_13";
print CSVF "\",\"";
print CSVF "$SUBTOTAL";
print CSVF "\",\"";
print CSVF "$TOTAL";
print CSVF "\",\"";
print CSVF "$SHIPPING";
print CSVF "\",\"";
print CSVF "$comment";
print CSVF "\"\n";
close CSVF;
}



# Send email conformation to the customer.....
open (MAIL,"|$mailprogram");
print MAIL "To: $b_email\n";
print MAIL "From: $youremail\n";
print MAIL "Subject: Thank You For Your Order With HEL Performance\n";
print MAIL "\n\n";
print MAIL "Thank You For Ordering From HEL Performance. A summary of your order appears below.\n";
print MAIL "\n";
print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n";
print MAIL " \n";
print MAIL " $b_first $b_last \n";
print MAIL " $b_addr \n";
print MAIL " $b_addr2 \n";
print MAIL " $b_city, $b_state $b_zip \n";
print MAIL " $b_phone \n";
print MAIL " $b_fax \n";
print MAIL " $b_email \n";
print MAIL " \n";
print MAIL " \n";
print MAIL "Qty Price(\$) Product ID - Product Name\n";
print MAIL "===================================================================== \n";
print MAIL "$QUANTITY_1 \$$PRICE_1 $ID_1 - $NAME_1 $ADDTLINFO_1 \n";
if( $NAME_2 ) {print MAIL "$QUANTITY_2 \$$PRICE_2 $ID_2 - $NAME_2 $ADDTLINFO_2 \n";}
if( $NAME_3 ) {print MAIL "$QUANTITY_3 \$$PRICE_3 $ID_3 - $NAME_3 $ADDTLINFO_3 \n";}
if( $NAME_4 ) {print MAIL "$QUANTITY_4 \$$PRICE_4 $ID_4 - $NAME_4 $ADDTLINFO_4 \n";}
if( $NAME_5 ) {print MAIL "$QUANTITY_5 \$$PRICE_5 $ID_5 - $NAME_5 $ADDTLINFO_5 \n";}
if( $NAME_6 ) {print MAIL "$QUANTITY_6 \$$PRICE_6 $ID_6 - $NAME_6 $ADDTLINFO_6 \n";}
if( $NAME_7 ) {print MAIL "$QUANTITY_7 \$$PRICE_7 $ID_7 - $NAME_7 $ADDTLINFO_7 \n";}
if( $NAME_8 ) {print MAIL "$QUANTITY_8 \$$PRICE_8 $ID_8 - $NAME_8 $ADDTLINFO_8 \n";}
if( $NAME_9 ) {print MAIL "$QUANTITY_9 \$$PRICE_9 $ID_9 - $NAME_9 $ADDTLINFO_9 \n";}
if( $NAME_10 ){print MAIL "$QUANTITY_10 \$$PRICE_10 $ID_10 - $NAME_10 $ADDTLINFO_10 \n";}
if( $NAME_11 ){print MAIL "$QUANTITY_11 \$$PRICE_11 $ID_11 - $NAME_11 $ADDTLINFO_11 \n";}
if( $NAME_12 ){print MAIL "$QUANTITY_12 \$$PRICE_12 $ID_12 - $NAME_12 $ADDTLINFO_12 \n";}
if( $NAME_13 ){print MAIL "$QUANTITY_13 \$$PRICE_13 $ID_13 - $NAME_13 $ADDTLINFO_13 \n";}
print MAIL "===================================================================== \n";
print MAIL "SUBTOTAL: $SUBTOTAL \n";
print MAIL "TOTAL: $TOTAL \n";
print MAIL "\n";
print MAIL "FREIGHT: $SHIPPING \n";
print MAIL "\n\n";
print MAIL "Comments: \n";
print MAIL "--------- \n";
print MAIL "$comment \n";
print MAIL " \n";
close MAIL;


print "Content-type: text/html\n\n";

open (HEAD, $header);
@LINES = <HEAD>;
close HEAD;
print @LINES;

print "<h2>Thank you</h2>";
print "Thank you for your order from the HEL Performance Online Shop. You will receive a confirmation email of your order ";
print "momentarily. Please contact us via $youremail if you have any questions or concerns with the subject online order enquiry - Thank You.";
print "<P>";
print "<A HREF=\"$returnpage\" target=_top>Return Home</A>";
print "<P>";

open (FOOT, $footer);
@LINES = <FOOT>;
close FOOT;

print @LINES;

exit;
Simon Lane
 
Posts: 30
Joined: Wed Feb 05, 2003 1:18 pm
Location: UK

Justin...

Postby Simon Lane » Tue Mar 04, 2003 3:51 pm

Thanks for looking at this Justin

And thank you for the extra code - I will put that in as soon as I have sorted the CSV writing problem...

Thanks again

Simon
Simon Lane
 
Posts: 30
Joined: Wed Feb 05, 2003 1:18 pm
Location: UK

Postby Stefko » Wed Mar 05, 2003 4:02 am

You should use a path to the csv file, NOT a URL

Example

orders.csv (if in same directory as checkout.pl)
/files/orders.csv (if in a sub-directoy of cgi-bin)
sites/site51/web/private/files/orders.csv (Complete path from server to your file)

Hope this helps
KFL Technologies
Web-Enabled Solutions
e-Commerence Solutions
Stefko
Contributor / Guru
 
Posts: 833
Joined: Wed Sep 18, 2002 1:11 am
Location: Wichita, KS

Changed CSV File

Postby Simon Lane » Wed Mar 05, 2003 9:14 am

I changed the CSV file as suggested from http://www.h-e-l.co.uk/cgi-bin/orders.csv to just orders.csv but now it returns an error which it didn't before.

Any suggestions ?

Thanks



Simon
Simon Lane
 
Posts: 30
Joined: Wed Feb 05, 2003 1:18 pm
Location: UK

Postby Stefko » Wed Mar 05, 2003 1:42 pm

Looks like a Permissions Problem, set permissions to 755

Also upload a blank text file(orders.txt) ASCII not Binary,and rename it orders.csv, lets start fresh!!
KFL Technologies
Web-Enabled Solutions
e-Commerence Solutions
Stefko
Contributor / Guru
 
Posts: 833
Joined: Wed Sep 18, 2002 1:11 am
Location: Wichita, KS

Stefko

Postby Simon Lane » Wed Mar 05, 2003 7:35 pm

I saved an orders.txt ( notepad file ) and uploaded it to the cgi-bin in ASCII and then renamed it to orders.csv.

I then changed the attributes to 755 as suggested but the little beggar still refuses to be written to !!!

Any other ideas would be cool - sorry to be a pain in the arse on this one but I could really do with the help...

And what happens if you actually are a rat in the animal sense and you win the rat race ?
:lol:

regards


Simon
Simon Lane
 
Posts: 30
Joined: Wed Feb 05, 2003 1:18 pm
Location: UK


Return to Installation and Setup Problems

Who is online

Users browsing this forum: No registered users and 0 guests

cron