Simple form processing
Posted: Fri Nov 14, 2008 8:59 am
Hi, in my quest to learn php well, I have chosen to learn from several places of info. and samples. At the moment all I am attempting to do is use a very basic HTML form and send the data to a basic php page. In all the samples I have seen (all done pretty much the same way) it works, but of course not for me. I have even gone as far as copying the code for the 2 files exactly as in one of the samples. Just to get it to work. No good. It appears the field values are not being received by my php page leading me to get the error, "Notice: Undefined index:". This error shows for all the form fields. If someone could help me out I would REALLY appreciate it so much! The code for the 2 files is below:
Is there a configuration someplace I need to deal with? It doesn't make any sense to me that it works for some people but not me. Pretty frustrating. Thanks so much in advance for your assistance!!
Code: Select all
<head>
<title>Test form</title>
</head>
<body>
Please fill out this form to calculate total <br />
<br />
<form action = "calc.php" method = "GET">
Price:<input type = "text" name = "price" size = "10" />
<br /> <br />
Quantity:<input type = "text" name = "quantity" size = "10" />
<br /><br />
Tax:<input type ="text" name = "tax" size = "3" />
<br /><br />
Discount:<input type ="text" name = "Discount" size = "3" />
Shipping method<select name ="shipping">
<option value ="$5.00">Slow and steady</option>
<option value ="$8.95">Put a move on it!</option>
<option value ="$20.00">I need it yesterday!!</option>
</select>
<input type="hidden" name="SubmitCheck" value="sent" />
<br />
<br />
Number of payments to make: <input type ="text" name = "payments" size = "3" />
<br /><br />
<input type = "submit" name = "submit" value = "calculate!" />
</form>
</body>
</html>
The php page looks like this:
Code: Select all
<head>
<title>Calculate the input</title>
</head>
<body>
<?php
//in case register globals is disabled
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$discount = $_POST['discount'];
$tax = $_POST['tax'];
$shipping = $_POST['shipping'];
$payments = $_POST['payments'];
//Calculate
$total = $price * $quantity;
$total = $total + $shipping;
$total = $total - $discount;
//determine tax rate
$taxrate = $tax/100;
$taxrate = $taxrate + 1;
//factor in tax
$totale = $total * $taxrate;
//Calculate monthly payments
$monthly = $total/payments;
//print results
print "You have selected to purchae: <br />
<b>$quantity</b> Thing(s) at <br />
$<b>$price</b>. Shipping will be
$<b>$shipping</b> and the sales tax
for this purchase is<b>$tax</b><br />
After your$<b>$discount</b> discount,
the total cost is $<b>$totale</b>. <br />
Divided over <b>$payments</b> monthly payments
, that would be<b>$monthly</b> each!";
?>
</body>
</html>