PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
<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:
<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>
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!!
Last edited by zenix on Fri Nov 14, 2008 12:08 pm, edited 2 times in total.
1. Can you provide us with a dump of the database structure?
2. I notice you have whitespace between your tag elements and their values. I'm not sure if that matters, but it's certainly unconventional. For example, I would change this:
OHHHHH, I also just noticed that the form method you are using in the first file is GET, while the PHP file is looking for $_POST data. change $_POST to $_GET in the php (or change GET to POST in the HTML) and you should be fine.
Yeah, sorry. I was experimenting with the Get method. It was post originally. I forgot to change it. How would I run a dump on the database structure? Thank you for responding.
Actually, forget about the database structure. That was a brain fart . . . you're not even interacting with a db here. My bad.
I notice that you are looking for $_POST['discount'], but that there is no discount input in the form. That would lead to an index doesn't exist error. Try getting rid of that from the PHP file (or adding such an input to the form), run it and let me know what happens.
Did you get rid of all that extra space? Also, php is case-sensitive, so "Discount" and "discount" are different. Can you post here the current state of the code?
I have been programming HTML for a number of years now, the white space doesn't affect the code at all....but i tried anyway, figured what the heck. What have got to lose? Thanks again! The php code is the same as already posted.
Look we both know you obviously can't help me! I'll go somewhere else. My original problem had NOTHING to do with white space! You're obviously as clueless as I am.