HTML form doesn't POST to PHP processing file
Posted by: alpeabody (---.hsd1.md.comcast.net)
Date: March 08, 2010 08:21PM

I have just installed WAMPServer 2.0, and it got me most of the way to success!

I have a short PHP script I am using as a training aid. Here is the HTML that calls the script:

<form action="[localhost]; method="post">
<table border="0">
<tr bgcolor="#cccccc">
<td width="150">Item</td>
<td width="15">Quantity</td>
</tr>
<tr>

<td>Tires</td>
<td align="center"><input type="text" name="tireqty" size="3" maxlength="3" >
</tr>
<tr>
<td>Oil</td>
<td align="center"><input type="text" name="oilqty" size="3" maxlength="3" >
</tr>
<tr>

<td>Spark Plugs
</td>
<td align="center"><input type="text" name="sparkqty" size="3" maxlength="3">
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Order"
</td>
</tr>
</table>
</form>



And the PHP script it calls in Processorder.php is:


<html>

<head>

<title>Bob's Auto Parts-Order Results</title>

</head>

<body>

<h1>Bob's Auto Parts</h1>

<h2>Order Results</h2>

<?php

echo '<p>Order Processed.</p>';

$totalqty = 0;

$totalqty = $tireqty + $oilqty + $sparkqty;

echo "Items ordered: " , $totalqty , "<br>" ;



define('TIREPRICE', 79.95);

define('OILPRICE', 5.98);

define('SPARKPRICE', 4.95);



$tireprice = ($tireqty * TIREPRICE);

$oilprice = ($oilqty * OILPRICE) ;

$sparkprice = ($sparkqty * SPARKPRICE);







$taxrate = 0.06; //Sales tax is 6%

$totalbill=0.00;



$tirebill=0.00;

$tirebill=$tireqty*$tireprice;

echo "Tires: " , $tireqty , " at $" , $tireprice , " = $" , number_format($tirebill,2) , "<br>";

$oilbill=$oilqty*$oilprice;

echo "Quarts of Oil: " , $oilqty , " at $" , $oilprice , " = $" , number_format($oilbill,2) , "<br>";

$sparkbill=$sparkqty*$sparkprice;

echo "Spark Plugs: " , $sparkqty , " at $" , $sparkprice , " = $" , number_format($sparkbill,2) , "<br>";

$totalbill=($tirebill+$oilbill+$sparkbill);

echo "Total Taxable = $" , number_format($totalbill,2) , "<br>";

$totalbill*=(1+$taxrate);

echo "Total with Tax = $" , number_format($totalbill,2) , "<br>";

?>

</body>



</html>



On a Website I maintain as a volunteer, this same script, the only difference being that rather than "localhost" I call Processorder.php using the address provided by the web host, all works fine: I fill in the form, and click Submit Order, and the information is calculated and echoed to the screen.

On my computer with WAMP, the PHP script is called, but none of the data I enter is posted.

The output looks like this:

Bob's Auto Parts
Order Results

Order Processed.

Notice: Undefined variable: oilqty in C:\wamp\www\Processorder.php on line 11

Notice: Undefined variable: tireqty in C:\wamp\www\Processorder.php on line 11

Notice: Undefined variable: sparkqty in C:\wamp\www\Processorder.php on line 11
Items ordered: 0

Notice: Undefined variable: tireqty in C:\wamp\www\Processorder.php on line 18

Notice: Undefined variable: oilqty in C:\wamp\www\Processorder.php on line 19

Notice: Undefined variable: sparkqty in C:\wamp\www\Processorder.php on line 20

Notice: Undefined variable: tireqty in C:\wamp\www\Processorder.php on line 28
Tires:
Notice: Undefined variable: tireqty in C:\wamp\www\Processorder.php on line 29
at $0 = $0.00

Notice: Undefined variable: oilqty in C:\wamp\www\Processorder.php on line 30
Quarts of Oil:
Notice: Undefined variable: oilqty in C:\wamp\www\Processorder.php on line 31
at $0 = $0.00

Notice: Undefined variable: sparkqty in C:\wamp\www\Processorder.php on line 32
Spark Plugs:
Notice: Undefined variable: sparkqty in C:\wamp\www\Processorder.php on line 33
at $0 = $0.00
Total Taxable = $0.00
Total with Tax = $0.00



I am greatly encouraged by the fact that the PHP script is found and executed. Even seeing the Error Codes beat seeing a File Not Found error, or some indication that the PHP code was not run at all (my previous best result).

I strongly suspect what I have here is a problem in php.ini or something else in WAMP which is simply failing to record and post the data to Processorder.php.

Any ideas? What should I do next?

Thanks!

Al Peabody

Options: ReplyQuote
Re: HTML form doesn't POST to PHP processing file
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: March 08, 2010 08:27PM

weve seen this a couple of times. it from a really old book


first the script is wrong for new php
its missing some lines at the start of the php file

$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];



you need to actually take them for the $_POST array in new php


secondly some of those erros are only notices cos the files not written brilliantly. first make the change i said. if you still have errors ill explain how to get rid

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: HTML form doesn't POST to PHP processing file
Posted by: alpeabody (---.hsd1.md.comcast.net)
Date: March 09, 2010 05:26PM

Thanks to all who replied so quickly and helpfully. I understand the problem and have been able to get past it thanks to you guys.

Al

Options: ReplyQuote


Sorry, only registered users may post in this forum.