Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

HTML Checkboxes in Perl

normajeannormajean Posts: 39Member
I have a shopping cart written in Perl that I need to access the value of a checkbox and have it printed in an e-mail. I can get the checkbox to appear on the HTML page generated by the script, but when you actually go to submit the order, it returns an internal server error. What do I need to do? Any help would be greatly appreciated. Here is the code as it exists:

[code]
sub memail
{

if ($me_mail eq '1') {
open (MAIL, "|$mailprog

$myemail") || die "Can't open $mailprog!
";

print MAIL "Reply-to:

$contents{'email'}
";
print MAIL "From: $contents{'email'}
";
print MAIL

"Subject:Item Ordered

";
print MAIL "You have a new order

";
print

MAIL "From
";
print MAIL "$contents{'FirstName'} $contents{'LastName'}
";


print MAIL "Address: $contents{'StreetAddress'}
";
if ($contents{'Apt'}) {


print MAIL "Apt: $contents{'Apt'}
";
}
print MAIL "City:

$contents{'City'}, State: $contents{'State'}
";
print MAIL "ZIP:

$contents{'PostalCode'}, Phone: $contents{'Phone'}
";
print MAIL "Fax:

$contents{'Fax'} E-mail: $contents{'email'}
";
print MAIL "Pets Name:

$contents{'PetsName'}
";
print MAIL "Credit Card: $contents{'CardType'}

Number: $contents{'CardNumber'}
";
print MAIL "Expires:

$contents{'CardExpires'}
";

########################################This is the checkbox
print MAIL "MallCom Order:

$contents{'MallcomOrder'}
";
########################################

print MAIL "Their Order:
";

foreach $msg

(@msg) {
($mquantity, $mprice, $mitem) = split(/:/ , $msg);

print MAIL

"$mquantity $mitem at $$mprice each
";

}

&TotalIt;
print MAIL "Total:

$";
print MAIL "$TheTotal
";

close (MAIL);
}
else {
print

"Content-type: text/html

";
print "

You can't check

out, because there are no items in your cart
";
exit;
}
}

[/code]

Thanks so much!
Norma :)

Comments

  • JonathanJonathan Posts: 2,914Member
    Norma,

    If you set the value property of a checkbox to something, then when the form is submitted, if that check box has been ticked, then the variable $contents{'checkboxname'} will contain that value. If it is not ticked, $contents{'checkboxname'} will be empty.

    Hope this helps somehow... :)

    Jonathan

    ------------------------------------------
    Count downloads from your site for free!
    http://www.downloadcounter.com/

  • normajeannormajean Posts: 39Member
    Thanks, Jonathan. I did do that, and found out that the e-mail did send, but for some reason it is giving the user an internal server error. I tried both a radio button and a checkbox this way...any suggestions as to why is would send the message and give the user the error instead of creating the "thank you" page?

    Norma :)

    : Norma,
    :
    : If you set the value property of a checkbox to something, then when the form is submitted, if that check box has been ticked, then the variable $contents{'checkboxname'} will contain that value. If it is not ticked, $contents{'checkboxname'} will be empty.
    :
    : Hope this helps somehow... :)
    :
    : Jonathan
    :
    : ------------------------------------------
    : Count downloads from your site for free!
    : http://www.downloadcounter.com/
    :
    :

  • JonathanJonathan Posts: 2,914Member
    Hi,

    Unless you are doing it in another bit of the script, I cannot see anywhere that you are returning a "Order Successful" message after the mail has been sent. If this is not happenning, then the server will say Internal Server Error because the script has terminated without sending any output or a valid set of HTTP headers.

    Let me know if I need to explain better...

    Jonathan

    : Thanks, Jonathan. I did do that, and found out that the e-mail did send, but for some reason it is giving the user an internal server error. I tried both a radio button and a checkbox this way...any suggestions as to why is would send the message and give the user the error instead of creating the "thank you" page?
    :
    : Norma :)
    :
    : : Norma,
    : :
    : : If you set the value property of a checkbox to something, then when the form is submitted, if that check box has been ticked, then the variable $contents{'checkboxname'} will contain that value. If it is not ticked, $contents{'checkboxname'} will be empty.
    : :
    : : Hope this helps somehow... :)
    : :
    : : Jonathan
    : :
    : : ------------------------------------------
    : : Count downloads from your site for free!
    : : http://www.downloadcounter.com/
    : :
    : :
    :
    :


    ------------------------------------------
    Count downloads from your site for free!
    http://www.downloadcounter.com/

  • normajeannormajean Posts: 39Member
    Jonathan: Here is the majority of the script (with all but the portion where the variables are configured/declared):

    [code]
    #####################

    &parse;

    $referer = $ENV{'HTTP_REFERER'};

    if ($contents{'action'} eq "AddItem") {
    &AddItem;
    }

    if ($contents{'action'} eq "RemoveItem") {
    &RemoveItem;
    }

    if ($contents{'action'} eq "ViewCart") {
    &ViewCart;
    }

    if ($contents{'action'} eq "MailIt") {
    &MailIt;
    }

    ###########


    sub MailIt {
    if (&GetCookies('cart')) {




    $mailcookie = "$Cookies{'cart'}";
    $tobeadded = $mailcookie;
    @msg = split(/|/, $mailcookie);

    &memail;
    &themmail;
    print "Content-type: text/html

    ";
    print "

    Order sent

    ";
    print "Your order has been sent. Thank you very much for your order.
    ";
    exit;


    }else{
    print "Content-type: text/html

    ";
    print "

    We're sorry

    ";
    print "You can't view your cart, because you don't have one.
    ";
    }
    }

    ############ MEMAIL SUBROUTINE ############
    # sends email to $myemail (you) informing you
    # that someone has used this script. IF you don't
    # want email, set the me_mail value to 0.

    sub memail
    {

    if ($me_mail eq '1') {
    open (MAIL, "|$mailprog $myemail") || die "Can't open $mailprog!
    ";

    print MAIL "Reply-to: $contents{'email'}
    ";
    print MAIL "From: $contents{'email'}
    ";
    print MAIL "Subject:Item Ordered

    ";
    print MAIL "You have a new order

    ";
    print MAIL "From
    ";
    print MAIL "$contents{'FirstName'} $contents{'LastName'}
    ";
    print MAIL "Address: $contents{'StreetAddress'}
    ";
    if ($contents{'Apt'}) {
    print MAIL "Apt: $contents{'Apt'}
    ";
    }
    print MAIL "City: $contents{'City'}, State: $contents{'State'}
    ";
    print MAIL "ZIP: $contents{'PostalCode'}, Phone: $contents{'Phone'}
    ";
    print MAIL "Fax: $contents{'Fax'} E-mail: $contents{'email'}
    ";
    print MAIL "Pets Name: $contents{'PetsName'}
    ";
    print MAIL "Credit Card: $contents{'CardType'} Number: $contents{'CardNumber'}
    ";
    print MAIL "Expires: $contents{'CardExpires'}
    ";

    #################################################################
    #########################################Here is my checkbox in e-mail

    print MAIL "MallCom Order: $contents{'MallcomOrder'}
    ";

    #################################################################
    print MAIL "Their Order:
    ";

    foreach $msg (@msg) {

    ($mquantity, $mprice, $mitem) = split(/:/ , $msg);

    print MAIL "$mquantity $mitem at $$mprice each
    ";

    }

    &TotalIt;
    print MAIL "Total: $";
    print MAIL "$TheTotal
    ";

    close (MAIL);
    }
    else {
    print "Content-type: text/html

    ";
    print "

    You can't check out, because there are no items in your cart
    ";
    exit;
    }
    }

    ############ THEMMAIL SUBROUTINE ############
    # This sends email to the person who ordered from you.
    sub themmail
    {

    if ($them_mail eq '1' && $contents{'email'}) {
    open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!
    ";

    print MAIL "To: $contents{'email'}
    ";
    print MAIL "From: $from_mail
    ";
    print MAIL "Subject: Thank you!

    ";
    print MAIL "Dear $contents{'FirstName'},

    ";
    print MAIL "Thank you for your order from Dog's Deli. We appreciate your business! Sales tax will be added to all Ohio orders. Dog's Deli proudly boasts a flat shipping fee of 4.95 regardless of order quantity!
    ";
    close (MAIL);
    }
    }

    #################


    sub CheckOut {
    print "
    ";
    print "Please complete your billing and shipping information below ONLY once your order is complete.";
    print "Continue shopping
    ";
    print "image
    Please fill out the shipping information only prior to placing your order.
    ";
    print "Your first name:Last name:
    ";
    print "Street AddressApt. Number
    ";
    print "CityState
    ";
    print "Postal CodePhone
    ";
    print "E-mailFax
    ";
    print "Credit card typeVisaMasterCardAmerican ExpressDiscover
    ";
    print "Card number
    ";
    print "Card expires:
    ";
    print "*Name Of Pet
    (for birthday cake orders):
    ";

    #############################################################
    ##############################Here is the checkbox on the form

    print "Yes, I was referred by Mall.com!
    ";

    #############################################################

    print "
    ";
    print "Shipping Charges: All orders, regardless of quantity or order total, is charged a flat shipping fee of $4.95
    ";
    print "Mail Us Your Order!
    Make checks payable to Dog's Deli and simply fill out this form, print it and mail it to:
    ";
    print "The Canine Castle
    1137 Dixie Hwy
    Rossford, OH 43460


    ";
    }




    ########
    sub ViewCart {
    if (&GetCookies('cart')) {

    print "Content-type: text/html
    ";

    #

    $viewcookie = "$Cookies{'cart'}";
    $tobeadded = $viewcookie;
    @chocolate = split(/|/, $viewcookie);

    print "

    ";
    print "You may need to refresh this page to get the latest look at your cart.

    ";

    print "Quan.ItemPrice
    ";
    $RemoveNumber=0;
    foreach $chocolate (@chocolate) {

    ($quantity, $price, $item) = split(/:/ , $chocolate);

    print "$quantity$item$$price eachRemove item
    ";
    $RemoveNumber++;
    }

    &TotalIt;
    print "Total, plus shipping and applicable sales tax:$";
    printf("%.2f", $TheTotal);
    print "

    ";
    print "
    ";
    &CheckOut;
    print "
    ";
    print "";




    }else{
    print "Content-type: text/html

    ";
    print "We're sorry

    ";
    print "You can't view your cart, because you don't have one.
    ";
    print "Continue shopping
    ";
    }
    }



    #######
    sub RemoveItem {

    if (&GetCookies('cart')) {
    (@ToBeModified) = split(/|/, $Cookies{'cart'});
    $KillNumber = $contents{'number'};
    splice(@ToBeModified,$KillNumber,1,());

    &SetCookies('cart',@ToBeModified);

    print "Content-type: text/html

    ";
    print "Deleted

    The Item has been deleted

    ";
    print "Your cart now contains:
    ";
    print "
    ";


    foreach $ToBeModified (@ToBeModified) {


    ($quantity, $price, $item) = split(/:/ , $ToBeModified);

    print "
    ";
    $RemoveNumber++;
    $tobeadded = $ToBeModified;
    } #end foreach
    &TotalIt;

    print "
    ";
    print "
    QuanItemPrice
    $quantity$item$$price eachRemove item
    Total, not including shipping and applicable sales tax:$";
    printf("%.2f", $TheTotal);
    print "
    ";
    &CheckOut;
    print "
    ";
    print "";
    } #end if
    else {
    print "You must have items in your cart to delete them.
    ";
    print "Continue shopping
    ";
    exit;
    } #end else
    } #end sub


    #######
    sub TotalIt {

    $RunningTotal = 0;

    (@tobetotaled) = split(/|/, $tobeadded);

    foreach $tobetotaled (@tobetotaled) {
    ($HowMany, $HowMuch, $What) = split(/:/, $tobetotaled);
    $ItemTotal = $HowMany * $HowMuch;
    $RunningTotal = $RunningTotal + $ItemTotal;
    }
    $TheTotal = $RunningTotal;
    }
    ##### end TotalIt subroutine



    sub AddItem {
    if (&GetCookies('cart')) {

    print "Content-type: text/html
    ";

    #

    $tobeadded = "$Cookies{'cart'}" . "|" . "$contents{'quantity'}" . ":" . "$contents{'price'}" . ":" . "$contents{'item'}";

    &SetCookies('cart',$tobeadded);


    &TotalIt;

    # End the headers sent to browser. #

    print "
    ";

    print "Item added
    ";
    print "
    ";
    print "

    Your item has been added!


    ";

    $oldcookie = "$Cookies{'cart'}";
    @dough = split(/|/, $oldcookie);


    print "You have added $contents{'quantity'} $contents{'item'} at $$contents{'price'} each to your cart, which already contained:
    ";
    print "
    ";
    $RemoveNumber=0;
    foreach $dough (@dough) {

    ($quantity, $price, $item) = split(/:/ , $dough);

    print "
    ";
    $RemoveNumber++;
    }


    print "
    ";
    print "
    Quan.ItemPrice
    $quantity$item$$price eachRemove item
    Total, not including shipping and applicable sales tax:$";
    printf("%.2f", $TheTotal);
    print "
    ";
    &CheckOut;
    print "
    ";
    print "";
    }

    # this is if they are placing the first item in the cart
    else {


    print "Content-type: text/html
    ";


    $newitem = "$contents{'quantity'}" . ":" . "$contents{'price'}" . ":" . "$contents{'item'}";


    &SetCookies('cart',$newitem);

    # End the headers sent to browser. #
    print "
    ";

    #
    print "Item added
    ";
    print "

    Item added

    ";
    print "You have added $contents{'quantity'} $contents{'item'} at $$contents{'price'} each to your cart.
    ";

    $NewQuantity = $contents{'quantity'};
    $NewPrice = $contents{'price'};
    $NewTotal = $NewQuantity * $NewPrice;
    print "

    Your total is ";
    printf("%.2f", $NewTotal);

    &CheckOut;
    print "
    ";
    print "
    ";
    }

    }
    #### end AddItem subroutine



    sub parse
    {
    read(STDIN, $input, $ENV{'CONTENT_LENGTH'});

    $input = $ENV{'QUERY_STRING'} if $ENV{'QUERY_STRING'};

    @pairs = split(/&/, $input);

    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);

    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    $contents{$name} = $value;

    }
    }
    [/code]

    Thanks for your help!

    Norma :)

  • JonathanJonathan Posts: 2,914Member
    Norma,

    OK, I can't immediately see what is wrong but try putting this bit:-

    [code]
    print "Content-type: text/html

    ";
    print "

    Order sent

    ";
    print "Your order has been sent. Thank you very much for your order.
    ";
    [/code]

    Before:

    [code]
    &memail;
    &themmail;
    [/code]

    Just to make sure that nothing is being send before the output. Alternatively, but this line somewhere before $referer = $ENV{'HTTP_REFERER'}; line:-
    print "Content-type: text/html

    ";
    Then you will always know that a header has been printed properly. :)

    Any good?

    Jonathan

    : Jonathan: Here is the majority of the script (with all but the portion where the variables are configured/declared):
    :
    : [code]
    : #####################
    :
    : &parse;
    :
    : $referer = $ENV{'HTTP_REFERER'};
    :
    : if ($contents{'action'} eq "AddItem") {
    : &AddItem;
    : }
    :
    : if ($contents{'action'} eq "RemoveItem") {
    : &RemoveItem;
    : }
    :
    : if ($contents{'action'} eq "ViewCart") {
    : &ViewCart;
    : }
    :
    : if ($contents{'action'} eq "MailIt") {
    : &MailIt;
    : }
    :
    : ###########
    :
    :
    : sub MailIt {
    : if (&GetCookies('cart')) {
    :
    :
    :
    :
    : $mailcookie = "$Cookies{'cart'}";
    : $tobeadded = $mailcookie;
    : @msg = split(/|/, $mailcookie);
    :
    : &memail;
    : &themmail;
    : print "Content-type: text/html

    ";
    : print "

    Order sent

    ";
    : print "Your order has been sent. Thank you very much for your order.
    ";
    : exit;
    :
    :
    : }else{
    : print "Content-type: text/html

    ";
    : print "

    We're sorry

    ";
    : print "You can't view your cart, because you don't have one.
    ";
    : }
    : }
    :
    : ############ MEMAIL SUBROUTINE ############
    : # sends email to $myemail (you) informing you
    : # that someone has used this script. IF you don't
    : # want email, set the me_mail value to 0.
    :
    : sub memail
    : {
    :
    : if ($me_mail eq '1') {
    : open (MAIL, "|$mailprog $myemail") || die "Can't open $mailprog!
    ";
    :
    : print MAIL "Reply-to: $contents{'email'}
    ";
    : print MAIL "From: $contents{'email'}
    ";
    : print MAIL "Subject:Item Ordered

    ";
    : print MAIL "You have a new order

    ";
    : print MAIL "From
    ";
    : print MAIL "$contents{'FirstName'} $contents{'LastName'}
    ";
    : print MAIL "Address: $contents{'StreetAddress'}
    ";
    : if ($contents{'Apt'}) {
    : print MAIL "Apt: $contents{'Apt'}
    ";
    : }
    : print MAIL "City: $contents{'City'}, State: $contents{'State'}
    ";
    : print MAIL "ZIP: $contents{'PostalCode'}, Phone: $contents{'Phone'}
    ";
    : print MAIL "Fax: $contents{'Fax'} E-mail: $contents{'email'}
    ";
    : print MAIL "Pets Name: $contents{'PetsName'}
    ";
    : print MAIL "Credit Card: $contents{'CardType'} Number: $contents{'CardNumber'}
    ";
    : print MAIL "Expires: $contents{'CardExpires'}
    ";
    :
    : #################################################################
    : #########################################Here is my checkbox in e-mail
    :
    : print MAIL "MallCom Order: $contents{'MallcomOrder'}
    ";
    :
    : #################################################################
    : print MAIL "Their Order:
    ";
    :
    : foreach $msg (@msg) {
    :
    : ($mquantity, $mprice, $mitem) = split(/:/ , $msg);
    :
    : print MAIL "$mquantity $mitem at $$mprice each
    ";
    :
    : }
    :
    : &TotalIt;
    : print MAIL "Total: $";
    : print MAIL "$TheTotal
    ";
    :
    : close (MAIL);
    : }
    : else {
    : print "Content-type: text/html

    ";
    : print "

    You can't check out, because there are no items in your cart
    ";
    : exit;
    : }
    : }
    :
    : ############ THEMMAIL SUBROUTINE ############
    : # This sends email to the person who ordered from you.
    : sub themmail
    : {
    :
    : if ($them_mail eq '1' && $contents{'email'}) {
    : open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!
    ";
    :
    : print MAIL "To: $contents{'email'}
    ";
    : print MAIL "From: $from_mail
    ";
    : print MAIL "Subject: Thank you!

    ";
    : print MAIL "Dear $contents{'FirstName'},

    ";
    : print MAIL "Thank you for your order from Dog's Deli. We appreciate your business! Sales tax will be added to all Ohio orders. Dog's Deli proudly boasts a flat shipping fee of 4.95 regardless of order quantity!
    ";
    : close (MAIL);
    : }
    : }
    :
    : #################
    :
    :
    : sub CheckOut {
    : print "
    ";
    : print "Please complete your billing and shipping information below ONLY once your order is complete.";
    : print "Continue shopping
    ";
    : print "imagePlease fill out the shipping information only prior to placing your order.
    ";
    : print "Your first name:Last name:
    ";
    : print "Street AddressApt. Number
    ";
    : print "CityState
    ";
    : print "Postal CodePhone
    ";
    : print "E-mailFax
    ";
    : print "Credit card typeVisaMasterCardAmerican ExpressDiscover
    ";
    : print "Card number
    ";
    : print "Card expires:
    ";
    : print "*Name Of Pet(for birthday cake orders):
    ";
    :
    : #############################################################
    : ##############################Here is the checkbox on the form
    :
    : print "Yes, I was referred by Mall.com!
    ";
    :
    : #############################################################
    :
    : print "
    ";
    : print "Shipping Charges: All orders, regardless of quantity or order total, is charged a flat shipping fee of $4.95
    ";
    : print "Mail Us Your Order!Make checks payable to Dog's Deli and simply fill out this form, print it and mail it to:
    ";
    : print "The Canine Castle1137 Dixie Hwy Rossford, OH 43460
    ";
    : }
    :
    :
    :
    :
    : ########
    : sub ViewCart {
    : if (&GetCookies('cart')) {
    :
    : print "Content-type: text/html
    ";
    :
    : #
    :
    : $viewcookie = "$Cookies{'cart'}";
    : $tobeadded = $viewcookie;
    : @chocolate = split(/|/, $viewcookie);
    :
    : print "

    ";
    : print "You may need to refresh this page to get the latest look at your cart.
    ";
    :
    : print "Quan.ItemPrice
    ";
    : $RemoveNumber=0;
    : foreach $chocolate (@chocolate) {
    :
    : ($quantity, $price, $item) = split(/:/ , $chocolate);
    :
    : print "$quantity$item$$price eachRemove item
    ";
    : $RemoveNumber++;
    : }
    :
    : &TotalIt;
    : print "Total, plus shipping and applicable sales tax:$";
    : printf("%.2f", $TheTotal);
    : print "

    ";
    : print "
    ";
    : &CheckOut;
    : print "
    ";
    : print "";
    :
    :
    :
    :
    : }else{
    : print "Content-type: text/html

    ";
    : print "We're sorry

    ";
    : print "You can't view your cart, because you don't have one.
    ";
    : print "Continue shopping
    ";
    : }
    : }
    :
    :
    :
    : #######
    : sub RemoveItem {
    :
    : if (&GetCookies('cart')) {
    : (@ToBeModified) = split(/|/, $Cookies{'cart'});
    : $KillNumber = $contents{'number'};
    : splice(@ToBeModified,$KillNumber,1,());
    :
    : &SetCookies('cart',@ToBeModified);
    :
    : print "Content-type: text/html

    ";
    : print "Deleted

    The Item has been deleted

    ";
    : print "Your cart now contains:
    ";
    : print "
    ";
    :
    :
    : foreach $ToBeModified (@ToBeModified) {
    :
    :
    : ($quantity, $price, $item) = split(/:/ , $ToBeModified);
    :
    : print "
    ";
    : $RemoveNumber++;
    : $tobeadded = $ToBeModified;
    : } #end foreach
    : &TotalIt;
    :
    : print "
    ";
    : print "
    QuanItemPrice
    $quantity$item$$price eachRemove item
    Total, not including shipping and applicable sales tax:$";
    : printf("%.2f", $TheTotal);
    : print "
    ";
    : &CheckOut;
    : print "
    ";
    : print "";
    : } #end if
    : else {
    : print "You must have items in your cart to delete them.
    ";
    : print "Continue shopping
    ";
    : exit;
    : } #end else
    : } #end sub
    :
    :
    : #######
    : sub TotalIt {
    :
    : $RunningTotal = 0;
    :
    : (@tobetotaled) = split(/|/, $tobeadded);
    :
    : foreach $tobetotaled (@tobetotaled) {
    : ($HowMany, $HowMuch, $What) = split(/:/, $tobetotaled);
    : $ItemTotal = $HowMany * $HowMuch;
    : $RunningTotal = $RunningTotal + $ItemTotal;
    : }
    : $TheTotal = $RunningTotal;
    : }
    : ##### end TotalIt subroutine
    :
    :
    :
    : sub AddItem {
    : if (&GetCookies('cart')) {
    :
    : print "Content-type: text/html
    ";
    :
    : #
    :
    : $tobeadded = "$Cookies{'cart'}" . "|" . "$contents{'quantity'}" . ":" . "$contents{'price'}" . ":" . "$contents{'item'}";
    :
    : &SetCookies('cart',$tobeadded);
    :
    :
    : &TotalIt;
    :
    : # End the headers sent to browser. #
    :
    : print "
    ";
    :
    : print "Item added
    ";
    : print "
    ";
    : print "

    Your item has been added!


    ";
    :
    : $oldcookie = "$Cookies{'cart'}";
    : @dough = split(/|/, $oldcookie);
    :
    :
    : print "You have added $contents{'quantity'} $contents{'item'} at $$contents{'price'} each to your cart, which already contained:
    ";
    : print "
    ";
    : $RemoveNumber=0;
    : foreach $dough (@dough) {
    :
    : ($quantity, $price, $item) = split(/:/ , $dough);
    :
    : print "
    ";
    : $RemoveNumber++;
    : }
    :
    :
    : print "
    ";
    : print "
    Quan.ItemPrice
    $quantity$item$$price eachRemove item
    Total, not including shipping and applicable sales tax:$";
    : printf("%.2f", $TheTotal);
    : print "
    ";
    : &CheckOut;
    : print "
    ";
    : print "";
    : }
    :
    : # this is if they are placing the first item in the cart
    : else {
    :
    :
    : print "Content-type: text/html
    ";
    :
    :
    : $newitem = "$contents{'quantity'}" . ":" . "$contents{'price'}" . ":" . "$contents{'item'}";
    :
    :
    : &SetCookies('cart',$newitem);
    :
    : # End the headers sent to browser. #
    : print "
    ";
    :
    : #
    : print "Item added
    ";
    : print "

    Item added

    ";
    : print "You have added $contents{'quantity'} $contents{'item'} at $$contents{'price'} each to your cart.
    ";
    :
    : $NewQuantity = $contents{'quantity'};
    : $NewPrice = $contents{'price'};
    : $NewTotal = $NewQuantity * $NewPrice;
    : print "

    Your total is ";
    : printf("%.2f", $NewTotal);
    :
    : &CheckOut;
    : print "
    ";
    : print "
    ";
    : }
    :
    : }
    : #### end AddItem subroutine
    :
    :
    :
    : sub parse
    : {
    : read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
    :
    : $input = $ENV{'QUERY_STRING'} if $ENV{'QUERY_STRING'};
    :
    : @pairs = split(/&/, $input);
    :
    : foreach $pair (@pairs) {
    : ($name, $value) = split(/=/, $pair);
    :
    : $value =~ tr/+/ /;
    : $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    :
    : $contents{$name} = $value;
    :
    : }
    : }
    : [/code]
    :
    : Thanks for your help!
    :
    : Norma :)
    :


    ------------------------------------------
    Count downloads from your site for free!
    http://www.downloadcounter.com/

  • normajeannormajean Posts: 39Member
    Jonathan - I did do that and got an HTML page generated with the info:

    Order sent
    Your order has been sent. Thank you very much for your order. test... User unknown root... Can't create output root... Can't create output savemail: cannot save rejected email anywhere

    This didn't work, did it? :D

    Thanks for all of your help. I think I am just going to contact tech support where I bought the script from and have them fix it...what started out as an interesting challenge has become all challenge, not much interesting.

    Thanks, again.
    Norma :)

    : Norma,
    :
    : OK, I can't immediately see what is wrong but try putting this bit:-
    :
    : [code]
    : print "Content-type: text/html

    ";
    : print "

    Order sent

    ";
    : print "Your order has been sent. Thank you very much for your order.
    ";
    : [/code]
    :
    : Before:
    :
    : [code]
    : &memail;
    : &themmail;
    : [/code]
    :
    : Just to make sure that nothing is being send before the output. Alternatively, but this line somewhere before $referer = $ENV{'HTTP_REFERER'}; line:-
    : print "Content-type: text/html

    ";
    : Then you will always know that a header has been printed properly. :)
    :
    : Any good?
    :
    : Jonathan
    :
    : : Jonathan: Here is the majority of the script (with all but the portion where the variables are configured/declared):
    : :
    : : [code]
    : : #####################
    : :
    : : &parse;
    : :
    : : $referer = $ENV{'HTTP_REFERER'};
    : :
    : : if ($contents{'action'} eq "AddItem") {
    : : &AddItem;
    : : }
    : :
    : : if ($contents{'action'} eq "RemoveItem") {
    : : &RemoveItem;
    : : }
    : :
    : : if ($contents{'action'} eq "ViewCart") {
    : : &ViewCart;
    : : }
    : :
    : : if ($contents{'action'} eq "MailIt") {
    : : &MailIt;
    : : }
    : :
    : : ###########
    : :
    : :
    : : sub MailIt {
    : : if (&GetCookies('cart')) {
    : :
    : :
    : :
    : :
    : : $mailcookie = "$Cookies{'cart'}";
    : : $tobeadded = $mailcookie;
    : : @msg = split(/|/, $mailcookie);
    : :
    : : &memail;
    : : &themmail;
    : : print "Content-type: text/html

    ";
    : : print "

    Order sent

    ";
    : : print "Your order has been sent. Thank you very much for your order.
    ";
    : : exit;
    : :
    : :
    : : }else{
    : : print "Content-type: text/html

    ";
    : : print "

    We're sorry

    ";
    : : print "You can't view your cart, because you don't have one.
    ";
    : : }
    : : }
    : :
    : : ############ MEMAIL SUBROUTINE ############
    : : # sends email to $myemail (you) informing you
    : : # that someone has used this script. IF you don't
    : : # want email, set the me_mail value to 0.
    : :
    : : sub memail
    : : {
    : :
    : : if ($me_mail eq '1') {
    : : open (MAIL, "|$mailprog $myemail") || die "Can't open $mailprog!
    ";
    : :
    : : print MAIL "Reply-to: $contents{'email'}
    ";
    : : print MAIL "From: $contents{'email'}
    ";
    : : print MAIL "Subject:Item Ordered

    ";
    : : print MAIL "You have a new order

    ";
    : : print MAIL "From
    ";
    : : print MAIL "$contents{'FirstName'} $contents{'LastName'}
    ";
    : : print MAIL "Address: $contents{'StreetAddress'}
    ";
    : : if ($contents{'Apt'}) {
    : : print MAIL "Apt: $contents{'Apt'}
    ";
    : : }
    : : print MAIL "City: $contents{'City'}, State: $contents{'State'}
    ";
    : : print MAIL "ZIP: $contents{'PostalCode'}, Phone: $contents{'Phone'}
    ";
    : : print MAIL "Fax: $contents{'Fax'} E-mail: $contents{'email'}
    ";
    : : print MAIL "Pets Name: $contents{'PetsName'}
    ";
    : : print MAIL "Credit Card: $contents{'CardType'} Number: $contents{'CardNumber'}
    ";
    : : print MAIL "Expires: $contents{'CardExpires'}
    ";
    : :
    : : #################################################################
    : : #########################################Here is my checkbox in e-mail
    : :
    : : print MAIL "MallCom Order: $contents{'MallcomOrder'}
    ";
    : :
    : : #################################################################
    : : print MAIL "Their Order:
    ";
    : :
    : : foreach $msg (@msg) {
    : :
    : : ($mquantity, $mprice, $mitem) = split(/:/ , $msg);
    : :
    : : print MAIL "$mquantity $mitem at $$mprice each
    ";
    : :
    : : }
    : :
    : : &TotalIt;
    : : print MAIL "Total: $";
    : : print MAIL "$TheTotal
    ";
    : :
    : : close (MAIL);
    : : }
    : : else {
    : : print "Content-type: text/html

    ";
    : : print "

    You can't check out, because there are no items in your cart
    ";
    : : exit;
    : : }
    : : }
    : :
    : : ############ THEMMAIL SUBROUTINE ############
    : : # This sends email to the person who ordered from you.
    : : sub themmail
    : : {
    : :
    : : if ($them_mail eq '1' && $contents{'email'}) {
    : : open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!
    ";
    : :
    : : print MAIL "To: $contents{'email'}
    ";
    : : print MAIL "From: $from_mail
    ";
    : : print MAIL "Subject: Thank you!

    ";
    : : print MAIL "Dear $contents{'FirstName'},

    ";
    : : print MAIL "Thank you for your order from Dog's Deli. We appreciate your business! Sales tax will be added to all Ohio orders. Dog's Deli proudly boasts a flat shipping fee of 4.95 regardless of order quantity!
    ";
    : : close (MAIL);
    : : }
    : : }
    : :
    : : #################
    : :
    : :
    : : sub CheckOut {
    : : print "
    ";
    : : print "Please complete your billing and shipping information below ONLY once your order is complete.";
    : : print "Continue shopping
    ";
    : : print "imagePlease fill out the shipping information only prior to placing your order.
    ";
    : : print "Your first name:Last name:
    ";
    : : print "Street AddressApt. Number
    ";
    : : print "CityState
    ";
    : : print "Postal CodePhone
    ";
    : : print "E-mailFax
    ";
    : : print "Credit card typeVisaMasterCardAmerican ExpressDiscover
    ";
    : : print "Card number
    ";
    : : print "Card expires:
    ";
    : : print "*Name Of Pet(for birthday cake orders):
    ";
    : :
    : : #############################################################
    : : ##############################Here is the checkbox on the form
    : :
    : : print "Yes, I was referred by Mall.com!
    ";
    : :
    : : #############################################################
    : :
    : : print "
    ";
    : : print "Shipping Charges: All orders, regardless of quantity or order total, is charged a flat shipping fee of $4.95
    ";
    : : print "Mail Us Your Order!Make checks payable to Dog's Deli and simply fill out this form, print it and mail it to:
    ";
    : : print "The Canine Castle1137 Dixie Hwy Rossford, OH 43460
    ";
    : : }
    : :
    : :
    : :
    : :
    : : ########
    : : sub ViewCart {
    : : if (&GetCookies('cart')) {
    : :
    : : print "Content-type: text/html
    ";
    : :
    : : #
    : :
    : : $viewcookie = "$Cookies{'cart'}";
    : : $tobeadded = $viewcookie;
    : : @chocolate = split(/|/, $viewcookie);
    : :
    : : print "

    ";
    : : print "You may need to refresh this page to get the latest look at your cart.
    ";
    : :
    : : print "Quan.ItemPrice
    ";
    : : $RemoveNumber=0;
    : : foreach $chocolate (@chocolate) {
    : :
    : : ($quantity, $price, $item) = split(/:/ , $chocolate);
    : :
    : : print "$quantity$item$$price eachRemove item
    ";
    : : $RemoveNumber++;
    : : }
    : :
    : : &TotalIt;
    : : print "Total, plus shipping and applicable sales tax:$";
    : : printf("%.2f", $TheTotal);
    : : print "

    ";
    : : print "
    ";
    : : &CheckOut;
    : : print "
    ";
    : : print "";
    : :
    : :
    : :
    : :
    : : }else{
    : : print "Content-type: text/html

    ";
    : : print "We're sorry

    ";
    : : print "You can't view your cart, because you don't have one.
    ";
    : : print "Continue shopping
    ";
    : : }
    : : }
    : :
    : :
    : :
    : : #######
    : : sub RemoveItem {
    : :
    : : if (&GetCookies('cart')) {
    : : (@ToBeModified) = split(/|/, $Cookies{'cart'});
    : : $KillNumber = $contents{'number'};
    : : splice(@ToBeModified,$KillNumber,1,());
    : :
    : : &SetCookies('cart',@ToBeModified);
    : :
    : : print "Content-type: text/html

    ";
    : : print "Deleted

    The Item has been deleted

    ";
    : : print "Your cart now contains:
    ";
    : : print "
    ";
    : :
    : :
    : : foreach $ToBeModified (@ToBeModified) {
    : :
    : :
    : : ($quantity, $price, $item) = split(/:/ , $ToBeModified);
    : :
    : : print "
    ";
    : : $RemoveNumber++;
    : : $tobeadded = $ToBeModified;
    : : } #end foreach
    : : &TotalIt;
    : :
    : : print "
    ";
    : : print "
    QuanItemPrice
    $quantity$item$$price eachRemove item
    Total, not including shipping and applicable sales tax:$";
    : : printf("%.2f", $TheTotal);
    : : print "
    ";
    : : &CheckOut;
    : : print "
    ";
    : : print "";
    : : } #end if
    : : else {
    : : print "You must have items in your cart to delete them.
    ";
    : : print "Continue shopping
    ";
    : : exit;
    : : } #end else
    : : } #end sub
    : :
    : :
    : : #######
    : : sub TotalIt {
    : :
    : : $RunningTotal = 0;
    : :
    : : (@tobetotaled) = split(/|/, $tobeadded);
    : :
    : : foreach $tobetotaled (@tobetotaled) {
    : : ($HowMany, $HowMuch, $What) = split(/:/, $tobetotaled);
    : : $ItemTotal = $HowMany * $HowMuch;
    : : $RunningTotal = $RunningTotal + $ItemTotal;
    : : }
    : : $TheTotal = $RunningTotal;
    : : }
    : : ##### end TotalIt subroutine
    : :
    : :
    : :
    : : sub AddItem {
    : : if (&GetCookies('cart')) {
    : :
    : : print "Content-type: text/html
    ";
    : :
    : : #
    : :
    : : $tobeadded = "$Cookies{'cart'}" . "|" . "$contents{'quantity'}" . ":" . "$contents{'price'}" . ":" . "$contents{'item'}";
    : :
    : : &SetCookies('cart',$tobeadded);
    : :
    : :
    : : &TotalIt;
    : :
    : : # End the headers sent to browser. #
    : :
    : : print "
    ";
    : :
    : : print "Item added
    ";
    : : print "
    ";
    : : print "

    Your item has been added!


    ";
    : :
    : : $oldcookie = "$Cookies{'cart'}";
    : : @dough = split(/|/, $oldcookie);
    : :
    : :
    : : print "You have added $contents{'quantity'} $contents{'item'} at $$contents{'price'} each to your cart, which already contained:
    ";
    : : print "
    ";
    : : $RemoveNumber=0;
    : : foreach $dough (@dough) {
    : :
    : : ($quantity, $price, $item) = split(/:/ , $dough);
    : :
    : : print "
    ";
    : : $RemoveNumber++;
    : : }
    : :
    : :
    : : print "
    ";
    : : print "
    Quan.ItemPrice
    $quantity$item$$price eachRemove item
    Total, not including shipping and applicable sales tax:$";
    : : printf("%.2f", $TheTotal);
    : : print "
    ";
    : : &CheckOut;
    : : print "
    ";
    : : print "";
    : : }
    : :
    : : # this is if they are placing the first item in the cart
    : : else {
    : :
    : :
    : : print "Content-type: text/html
    ";
    : :
    : :
    : : $newitem = "$contents{'quantity'}" . ":" . "$contents{'price'}" . ":" . "$contents{'item'}";
    : :
    : :
    : : &SetCookies('cart',$newitem);
    : :
    : : # End the headers sent to browser. #
    : : print "
    ";
    : :
    : : #
    : : print "Item added
    ";
    : : print "

    Item added

    ";
    : : print "You have added $contents{'quantity'} $contents{'item'} at $$contents{'price'} each to your cart.
    ";
    : :
    : : $NewQuantity = $contents{'quantity'};
    : : $NewPrice = $contents{'price'};
    : : $NewTotal = $NewQuantity * $NewPrice;
    : : print "

    Your total is ";
    : : printf("%.2f", $NewTotal);
    : :
    : : &CheckOut;
    : : print "
    ";
    : : print "
    ";
    : : }
    : :
    : : }
    : : #### end AddItem subroutine
    : :
    : :
    : :
    : : sub parse
    : : {
    : : read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
    : :
    : : $input = $ENV{'QUERY_STRING'} if $ENV{'QUERY_STRING'};
    : :
    : : @pairs = split(/&/, $input);
    : :
    : : foreach $pair (@pairs) {
    : : ($name, $value) = split(/=/, $pair);
    : :
    : : $value =~ tr/+/ /;
    : : $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    : :
    : : $contents{$name} = $value;
    : :
    : : }
    : : }
    : : [/code]
    : :
    : : Thanks for your help!
    : :
    : : Norma :)
    : :
    :
    :
    : ------------------------------------------
    : Count downloads from your site for free!
    : http://www.downloadcounter.com/
    :
    :

  • JonathanJonathan Posts: 2,914Member
    Hi,

    Yeah, looks like the script wasn't really up for the mail sending process churning out responses...ah, so you didn't write the script yourself? I was gonna say nicely laid out code...except for a lack of comments, but then, it ain't your code...LOL! :)

    BTW, if you ever need cheap custom scripts writing that work give me a shout...if you want... :)
    http://www.jwcs.net/webdesign/

    Have a nice day!

    Jonathan


    : Jonathan - I did do that and got an HTML page generated with the info:
    :
    : Order sent
    : Your order has been sent. Thank you very much for your order. test... User unknown root... Can't create output root... Can't create output savemail: cannot save rejected email anywhere
    :
    : This didn't work, did it? :D
    :
    : Thanks for all of your help. I think I am just going to contact tech support where I bought the script from and have them fix it...what started out as an interesting challenge has become all challenge, not much interesting.
    :
    : Thanks, again.
    : Norma :)
    :
    : : Norma,
    : :
    : : OK, I can't immediately see what is wrong but try putting this bit:-
    : :
    : : [code]
    : : print "Content-type: text/html

    ";
    : : print "

    Order sent

    ";
    : : print "Your order has been sent. Thank you very much for your order.
    ";
    : : [/code]
    : :
    : : Before:
    : :
    : : [code]
    : : &memail;
    : : &themmail;
    : : [/code]
    : :
    : : Just to make sure that nothing is being send before the output. Alternatively, but this line somewhere before $referer = $ENV{'HTTP_REFERER'}; line:-
    : : print "Content-type: text/html

    ";
    : : Then you will always know that a header has been printed properly. :)
    : :
    : : Any good?
    : :
    : : Jonathan
    : :



    ------------------------------------------
    Count downloads from your site for free!
    http://www.downloadcounter.com/

  • normajeannormajean Posts: 39Member
    Thanks for the compliment...I'll pass it along! lol

    I will put you in my favorites, because I am sure I will have a need in the future.

    This is my first exposure to Perl...I am not a natural programmer...every bit that I learn comes from lots of blood, sweat and tears...and swearing and pounding the keyboard! :D However, thanks to classes in C++, VB and JavaScript, I can do just enough to cause serious damage to an existing program. :)

    Norma :)

  • JonathanJonathan Posts: 2,914Member
    Norma,

    : Thanks for the compliment...I'll pass it along! lol
    LOL! :)

    : I will put you in my favorites, because I am sure I will have a need in the future.

    OK, yeah, great...I'm always happy to help.


    : This is my first exposure to Perl...I am not a natural programmer...every bit that I learn comes from lots of blood, sweat and tears...and swearing and pounding the keyboard! :D However, thanks to classes in C++, VB and JavaScript, I can do just enough to cause serious damage to an existing program. :)

    Yeah, I taught myself Perl from scratch...I know other stuff too, though. VB I know quite well...I started programming in BASIC years ago...ages back...on a BBC computer...when I was 8 years old! Heck, that WAS a long time ago... A friend described Perl as "crazy C++" - not sure how true that is, but personally I love it...

    Jonathan


    ------------------------------------------
    Count downloads from your site for free!
    http://www.downloadcounter.com/

Sign In or Register to comment.