Sam R.
Sam R.

Reputation: 63

HTML Form not passing data to php processor

learning PHP and have hit a wall early with passing data in an HTML form in to PHP. When I hit submit, the form page acts like it submits properly but when the processorder.php page opens, the data is not visible. When I do a dump on the page, I am able to see the values displayed but they are not showing in the script. Below is the code I'm using. I've searched online and at SO and feel like I've pretty much exhausted all options. Any assistance you can provide is much appreciated.

HTML:
<form action="processorder.php" method="POST">

<table>
    <tr>
        <td>Item</td>
        <td>Quantity</td>
    </tr>
    <tr>
        <td>Tires</td>
        <td><input type="text" name="tireqty" id="tireqty" size="3" /></td>
    </tr>
    <tr>
        <td>Oil</td>
        <td><input type="text" name="oilqty" id="oilqty" size="3" /></td>
    </tr>
    <tr>
        <td>Spark Plugs</td>
        <td><input type="text" name="sparkqty" id="sparkqty" size="3" /></td>
    </tr>
    <tr>
        <td colspan="2" text-align"2"><input type="submit" value="Submit Order">
        </td>
    </tr>
</table>

</form>



PHP:
<?php

var_dump( $_POST );

/*var_dump($GLOBALS);*/

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

/*echo phpinfo();*/

?>

<h1 />Bob's Auto Parts
<h2>Order Results</h2>

<?php

/*
ini_set('display_errors',1);  
error_reporting(E_ALL);
*/

   echo "<p>Your Order is as Follows: </p>";
   echo htmlspecialchars($tireqty).' tires<br />';  
   echo htmlspecialchars($oilqty).' bottles of oil<br />';
   echo htmlspecialchars($sparkqty).' spark plugs<br />';

    echo "<p>Order Processed at ";
    echo date('H:i, jS F Y');
    echo "</p>";

print_r($_POST);

/*var_dump($_REQUEST)*/

?>

Upvotes: 0

Views: 40

Answers (1)

Marcelo Mizuno
Marcelo Mizuno

Reputation: 61

Remove the $ of your $_POST methods. Change:

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

to:

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

Upvotes: 3

Related Questions