这是html orderform(orderform.html)
<!doctype html>
<html>
<head>
</head>
<body>
<form action='processorder.php' 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></td>
</tr>
<tr>
<td>Oil</td>
<td align=center><input type="text" name="oilqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td align=center><input type="text" name="sparkqty" size=3 maxlength=3></td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit value="submit order"></td>
</td>
</table>
</form>
这是流程订单表格(processorder.php)
<!doctype html>
<html>
<head>
<title>Bobs auto parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo "<p>Order processed at ";
echo date("1 jS \of F Y h:i:s: A");
echo "<br>";
echo "<p>Your order is as follows:";
echo "<br>";
echo $tireqty." tires<br>";
echo $oilqty." bottles of oil<br>";
echo $sparkqty." spark plugs<br>";
var_dump($_POST);
&GT;
当我在processorder.php上的var_dump $ _POST时,它说它们在数组中,但是当我尝试回显变量时,它给了我一个通知,说我试图继承的变量是未经分解的。请帮忙:(
答案 0 :(得分:4)
你必须回应这些:
if (isset($_POST['tireqty']))
{
echo $_POST['tireqty'];
}
if (isset($_POST['oilqty']))
{
echo $_POST['oilqty'];
}
if (isset($_POST['sparkqty']))
{
echo $_POST['sparkqty'];
}
答案 1 :(得分:0)
您需要从帖子地图中获取变量。
// set the variable $tireqty to what tireqty was set to in the post call
$tireqty = $_POST['tireqty'];
更好的是,检查轮胎是否已通过邮寄发送:
// set the variable $tireqty to what tireqty was set to in the post call, if it is unset then set an error message
$tireqty = isset($_POST['tireqty'])? $_POST['tireqty'] : "Error message";
这是一个非常糟糕和危险的方法(请不要尝试这个)是:
// any value passed in via post will get turned into a variable of the same name
extract($_POST);
答案 2 :(得分:0)
你没有定义你的变量,但我已经在代码检查中为你完成了这个。
<!doctype html>
<html>
<head>
</head>
<body>
<form action='processorder.php' 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></td>
</tr>
<tr>
<td>Oil</td>
<td align=center><input type="text" name="oilqty" size=3 maxlength=3></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td align=center><input type="text" name="sparkqty" size=3 maxlength=3></td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit value="submit order"></td>
</td>
</table>
</form>
<!doctype html>
<html>
<head>
<title>Bobs auto parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo "<p>Order processed at ";
echo date("1 jS \of F Y h:i:s: A");
echo "<br>";
/*I defined variables bellow */
$tireqty=(isset($_POST['tireqty']))? trim($_POST['tireqty']): '';
$oilqty=(isset($_POST['oilqty']))? trim($_POST['oilqty']): '';
$sparkqty=(isset($_POST['sparkqty']))? trim($_POST['sparkqty']): '';
echo "<p>Your order is as follows:";
echo "<br>";
echo $tireqty." tires<br>";
echo $oilqty." bottles of oil<br>";
echo $sparkqty." spark plugs<br>";
?>