PDA

View Full Version : html data posting to cgi


dabney
11-05-2005, 06:01 AM
Hello all new to cgi, I'm doing a html form that passes the information to cgi, for cgi to print out the information in html, really basic stuff I hope. it's all calculations.

So the html passes, but I don't think that cgi get's the information or I didn't code the cgi program correctly, so here is the cgi program, can someone tell me where I'm going wrong?

#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
my $total=param('total');

$finaltotal = 0;
$discount = 0;
$shipping = 0;
$sale = 0;
$amount = 0;

if ($total >=100)
{
$discount = $total * .20;
$amount = $total - $discount;

$sale = $amount * .07;
$shipping = $amount * .05;
$finaltotal = $total - $discount +$sale + $shipping;

}

else {

$amount = $total;

$sale = $amount * .07;
$shipping = $amount * .05;
$finaltotal = $total + $sale + $shipping;
}
print <<WHOLEPAGE;
<html><head><title>CheckOut</title></head>

<body>
<table border="1">
<tr>
<th>Here is your final totals:</th>
</tr>
<tr>

<td>Purchase Total:</td><td align="right">\$$total</td>
</tr>

<tr>
<td>20% Discount</td><td align="right"></td>\$$discount</td>
</tr>
<tr>


<td>Total order amount:</td><td align="right">\$$amount</td>
</tr>
<tr>


<td>NC sales Tax (7%)</td><td align="right">\$$sale</td>
</tr>
<tr>

<td>Shipping and Handling</td><td align="right">\$$shipping</td>
</tr>
<tr>

<tr>


<td>Total Amount Due</td><td align="right">\$$finaltotal</td>
</tr>
<tr>

</tr>
</table>

</body></html>

nkrgupta
11-05-2005, 06:53 AM
put the following line after printing the header and before grabbing the value of 'total' in the variable $total --

use CGI qw(:standard);

Go through http://search.cpan.org/~lds/CGI.pm-3.11/CGI.pm for a detailed explanation.