HTML表单不将数据传递给php处理器

时间:2017-12-09 04:18:53

标签: php html

学习PHP并尽早将HTML格式的数据传递给PHP。当我点击提交时,表单页面就像正确提交一样,但是当processorder.php页面打开时,数据不可见。当我在页面上进行转储时,我能够看到显示的值,但它们没有在脚本中显示。以下是我正在使用的代码。我已经在网上搜索过,感觉我已经筋疲力尽了。非常感谢您提供的任何帮助。

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)*/

?>

1 个答案:

答案 0 :(得分:3)

删除$ _POST方法的$。变化:

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

为:

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