#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    75
    Rep Power
    16

    No price output from my script???


    Hi,
    I have been working on my script and I thought I had it pretty much sewed up BUT theres no cost output when I run the script.

    I cant find a problem with it, would someone with greater experience than I point out the error in my script because there must be one somewhere.

    Cheers Charlie

    Code:
    #!perl
    
    
    #include the library for parsing input
    use CGI;
    
    
    #parse the form arguments into variables to hold data
    $forename=CGI:param("forename");
    $surname=CGI:param("surname");
    $address1=CGI:param("address1");
    $address2=CGI:param("address2");
    $ChosenItem=CGI:param("ChosenItem");
    $Auto=CGI:param("Auto");
    $Doll=CGI:param("Doll");
    $Shoes=CGI:param("Shoes");
    $Cards=CGI:param("Cards");
    $Jackets=CGI:param("Jackets");
    $Glasses=CGI:param("Glasses");
    $Suits=CGI::param("Suits");
    
    
    
    #variables to hold data
    if ( !($forename=CGI::param("forename")) )
    {
            #output error page if no data entered
            &outputErr("Please enter your forename - Hit the
            back button and enter the missing information");
    }
    if ( !($surname=CGI::param("surname")) )
    {
            #output error page if no data entered
            &outputErr("Please enter your surname - Hit the
            back button and enter the missing information");
    }
    if ( !($address1=CGI::param("address1")) )
    {
            #output error page if no data entered
            &outputErr("Please enter your address - Hit the
            back button and enter the missing information");
    }
    if ( !($address2=CGI::param("address2")) )
    {
            #output error page if no data entered
            &outputErr("Please enter your address - Hit the
            back button and enter the missing information");
    }
    
    
    
    
    open(FILE, "prices1.txt") || &outputErr("File access error");;
    @list=<FILE>;
    close FILE;
    
    if ($ChosenItem eq "Autographs") {
    $Cost = @list[0]* $Auto;
    
    }
    if ($ChosenItem eq "Talking doll") {
    $Cost = @list[1]* $Doll;
    
    }
    if ($ChosenItem eq "Blue suede shoes") {
    $Cost = @list[2]* $Shoes;
    
    }
    if ($ChosenItem eq "Playing cards") {
    $Cost = @list[3]* $Cards;
    
    }
    if ($ChosenItem eq "Elvis jacket") {
    $Cost = @list[4]* $Jackets;
    
    }
    if ($ChosenItem eq "Elvis sunglasses") {
    $Cost = @list[5]* $Glasses;
    }
    if ($ChosenItem eq "Elvis gold jumpsuit") {
    $Cost = @list[6]* $Suits;
    }
    
    #format the output
    $cost = sprintf("%.2f",$cost);
    
    #open file for appending or print error page if access denied
    open(OUT,">>orders.txt") || &outputErr("File Access Denied");
    #lock access
    flock(OUT,2);
    #write to the file
    print OUT "Forename:$forename \n";
    print OUT "Surname: $surname \n";
    print OUT "Address: $address1 \n";
    print OUT "Address: $address2 \n";
    print OUT "Item{s}: $ChosenItem Cost: $Cost \n";
    
    print OUT "Total Cost:  $Cost \n";
    print OUT "********************************************************* \n";
    #unlock access
    flock(OUT,8);
    #close the file
    close(OUT);
    
    #output web page
    print <<PAGE ;
    Content-type: text/html \n\n
    <html>
    <head>
    <title>SUCCESS</title>
    </head>
    Good Choice
    <body>
     <br>
     <br>
     <br>
    
    
    <body bgcolor="#000000" >
    <font color="white"><font size=+1>
    First Name:$forename <br>
    Surname:   $surname <br>
    <p>
    Address1:  $address1 <br>
    Address2:  $address2 <br>
    <p>
    You chose: $ChosenItem<br>
    
    
    <font size=+3><br><font size=3>Your choice costs $Cost</font></br>
    
    
    <center>Your order has been processed<br>
    Thankyou for shopping with us.</center></font>
    
    </body></html></i></font><br>
    
    
    PAGE
    
    #end the script
    exit 0;
    
    sub outputErr
    {
    #output error message
    print <<ERRPAGE ;
    Content-type: text/html\n\n
    <html>
    <head>
    <title>Error</title>
    </head>
    @_[0]
    </body></html>\n
    ERRPAGE
    
    #end script processing
    exit 0
    }
  2. #2
  3. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    1,614
    Rep Power
    17
    Try this:
    Code:
    #!/usr/bin/perl -w
    use strict;
    use CGI qw(:standard); #include the library for parsing input
    
    #parse the form arguments into variables to hold data
    my $forename   =param('forename');
    my $surname    =param('surname');
    my $address1   =param('address1');
    my $address2   =param('address2');
    my $ChosenItem =param('ChosenItem');
    my $Auto       =param('Auto');
    my $Doll       =param('Doll');
    my $Shoes      =param('Shoes');
    my $Cards      =param('Cards');
    my $Jackets    =param('Jackets');
    my $Glasses    =param('Glasses');
    my $Suits      =param('Suits');
    my @list       =();
    my $Cost;
    
    
    #variables to hold data
    if ( !$forename )
    {
    	#output error page if no data entered
    	&outputErr("Please enter your forename - Hit the
    	back button and enter the missing information");
    }
    if ( !$surname )
    {
    	#output error page if no data entered
    	&outputErr("Please enter your surname - Hit the
    	back button and enter the missing information");
    }
    if ( !$address1 )
    {
    	#output error page if no data entered
    	&outputErr("Please enter your address - Hit the
    	back button and enter the missing information");
    }
    if ( !$address2 )
    {
    	#output error page if no data entered
    	&outputErr("Please enter your address - Hit the
    	back button and enter the missing information");
    }
    
    open(FILE, "prices1.txt") || &outputErr("File access error");;
    @list=<FILE>;
    close FILE;
    
    	if ($ChosenItem eq "Autographs") {
    	$Cost = $list[0]* $Auto;
    	
    	}
    	if ($ChosenItem eq "Talking doll") {
    	$Cost = $list[1]* $Doll;
    
    	}
    	if ($ChosenItem eq "Blue suede shoes") {
    	$Cost = $list[2]* $Shoes;
    
    	}
    	if ($ChosenItem eq "Playing cards") {
    	$Cost = $list[3]* $Cards;
    
    	}
    	if ($ChosenItem eq "Elvis jacket") {
    	$Cost = $list[4]* $Jackets;
    
    	}
    	if ($ChosenItem eq "Elvis sunglasses") {
    	$Cost = $list[5]* $Glasses;
    	}
    	if ($ChosenItem eq "Elvis gold jumpsuit") {
    	$Cost = $list[6]* $Suits;
    	}
    
    #format the output
    $Cost = sprintf("%.2f",$Cost);
    
    #open file for appending or print error page if access denied
    open(OUT,">>orders.txt") || &outputErr("File Access Denied");
    #lock access
    flock(OUT,2);
    #write to the file
    	print OUT "Forename:$forename \n";
    	print OUT "Surname: $surname \n";
    	print OUT "Address: $address1 \n";
    	print OUT "Address: $address2 \n";
    	print OUT "Item{s}: $ChosenItem Cost: $Cost \n";
    
    	print OUT "Total Cost:  $Cost \n";
    	print OUT "********************************************************* \n";
    #unlock access
    flock(OUT,8);
    #close the file
    close(OUT);
    
    #output web page
    
    print header;
    print <<PAGE ;
    <html>
    <head>
    <title>SUCCESS</title>
    </head>
    Good Choice
    <body>
     <br>
     <br>
     <br>
    
    
    <body bgcolor="#000000" >
    <font color="white"><font size=+1>
    First Name:$forename <br>
    Surname:   $surname <br>
    <p>
    Address1:  $address1 <br>
    Address2:  $address2 <br>
    <p>
    You chose: $ChosenItem<br>
    
    
    <font size=+3><br><font size=3>Your choice costs $Cost</font></br>
    
    
    <center>Your order has been processed<br>
    Thankyou for shopping with us.</center></font>
    </body></html></i></font><br>
    PAGE
    
    #end the script
    exit 0;
    
    sub outputErr
    {
    #output error message
    print <<ERRPAGE ;
    <html>
    <head>
    <title>Error</title>
    </head>
    $_[0]
    </body></html>\n
    ERRPAGE
    
    #end script processing
    exit 0
    }
    And I thought you were a pizza seller
    webM

    for $i(0..20){for($j=0;$j<=$i;$j+=2){print pack(qq{H2},
    substr(qq{5f5745424d415354415f},$j,2));}print qq{\n};};
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    75
    Rep Power
    16

    Same Result


    Hi Webmasta,
    Thanks Ive tried your version and I get the same results 0.00 for the cost.

    Puzzling to say the least. Ill attach the form.
    Pizza seller no..a friend of mine is...Im trying to expand the capabilities of this set up.
    Cheers Charlie
    Attached Files
    Last edited by Charlie; November 12th, 2003 at 10:17 AM.
  6. #4
  7. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    1,614
    Rep Power
    17
    Did you say your script even worked??

    Seriously: try putting some $$ values in your form ... multiplying apples and grapes will always amount to $0..
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    75
    Rep Power
    16

    ??? I dont understand


    I cant catch your drift there mate, the values are read from the price.txt..can you explain this further to me please.

    I cant see the wood for the trees at the moment.
    Charlie
  10. #6
  11. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    1,614
    Rep Power
    17
    Sorry: I menat to say "try putting some [amount] values in your form "
    Code:
    <select name="Auto">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option> Get the drift?
          <option value="Auto4">4</option>
          <option value="Auto5">5</option>
          <option value="Auto6">6</option>
          <option value="Auto7">7</option>
          <option value="Auto8">8</option>
          <option value="Auto9">9</option>
          <option value="Auto10">10</option>
    </select>
    Because in reality the script is trying to multiply Auto1 etc by the price == apples and grapes = 0.
    webM

    for $i(0..20){for($j=0;$j<=$i;$j+=2){print pack(qq{H2},
    substr(qq{5f5745424d415354415f},$j,2));}print qq{\n};};
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    75
    Rep Power
    16

    I get it


    Oh I get it, Im not used to using drop down lists, I never even considered there may be a problem there.

    I might have another couple of questions in a while if you could guide me I would be grateful.
    For example if I only have a limited amount of stock how would I go about checking that I hadnt sold all of my stock or the client hadnt ordered more than I have, say if I had a txt file with the stock amounts for each item in it.


    Cheers Charlie
    Last edited by Charlie; November 12th, 2003 at 10:54 AM.
  14. #8
  15. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    1,614
    Rep Power
    17
    Thats known as inventory control .. you might want to consider putting that project in the hands of a pro... many issues to deal with ... not forgetting your script above is a major security hazard as it stands... wouldnt let that on my server for one sec in its present condition

    If you just want a quick and nasty solution, then setup an inventory field within the present db and let logic dictate how technology will do the math.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    75
    Rep Power
    16

    Thanks


    I doubt ill get it to work but I will give it a go. I never thought about security issues, funny thing is I have run a few of my own insecure scripts on my PC without a problem.

    Just the usual attempted IIS exploits.

    Anyway if I cant manage to do the stock control probably one of the guys here can point me in the right direction
    Cheers Charlie

IMN logo majestic logo threadwatch logo seochat tools logo