我没有从第一个循环获取信息到第二个循环,它给出了一个错误,例如:注意:未定义的索引:txtprice 在..
问题是我无法将if(isset($_POST['getdata']))
中的数据导入if(isset($_POST['addto']))
以回显并进行计算
<html>
<body>
<form method="post" action="newcal.php">
<table>
<tr>
<td> Item #: </td>
<td> <input type=text name= txtitem > <br> </td>
<td>
</td>
<td> <fieldset style = "width:60px">
<input type=submit value = "Get Data" name= getdata>
<input type=submit value = "Add to Cart" name= addto>
<input type=submit value = "Get Total" name= gettotal>
</fieldset>
</td>
</tr>
</table>
</form>
<?php
$item = (isset($_POST['txtitem']) ? intval($_POST['txtitem']) : null);
$stuff = array(
array("id" => 1,"name" => "Apples","price" => 50 ),
array("id" => 2,"name" => "Pineapples","price" => 125 ),
array("id" => 3,"name" => "Mango","price" => 35 ),
array("id" => 4,"name" => "Banana","price" => 25 ),
array("id" => 5,"name" => "Naseberry","price" => 38 ));
if(isset($_POST['getdata']))
{
foreach ($stuff as $row)
{
if ($row['id'] == $item)
{
$name = $row['name'];
$price = $row['price'];
echo "Item Number:    <input type=\"text\" name=\"txtinum\" VALUE=\"$item\">"."</br>"."</br>";
echo "Name:                <input type=\"text\" name=\"txtname\" VALUE=\"$name\">"."</br>"."</br>";
echo "Price :                <input type=\"text\" name=\"txtprice\" VALUE=\"$price\">"."</br>"."</br>";
echo "Quantity:           <input type=\"text\" name=\"txtquant\">"."</br>"."</br>";
}
}
}
if(isset($_POST['addto']))
{
$quant = isset($_POST['txtquant']);
$cal = $price * $quant;
echo "<table width='360px' border='1' cellpadding='2'>";
echo "<tr>";
echo "<th> Item ID</th>" ;
echo "<th> Name</th>";
echo"<th> Price</th>";
echo"<th> Quantity</th>";
echo"<th> Sub Total </th>";
echo "</tr>";
echo "<tr>";
echo "<td> $itemnum </td>";
echo "<td> $name </td>";
echo "<td> $price </td>";
echo "<td> $quant </td>";
echo "<td> </td>";
echo "<tr>";
}
?>
</body>
</html>