这是我的问题:我从数据库中获取了STOCK的值并在文本框中输入了一个值,问题是当我尝试计算系统时无法识别或说未定义的索引:库存
这是从值到计算的语法:
<td><input type = "text" name = "stock[]" size = "5" value = '<?php echo $row['stock']; ?>' disabled></td>
<td><input type = 'text' name = 'stockin[]' size = '5'></td>
<td><input type ="submit" name = "btn" value = "re-stock"></td>
这是我放在 标签
之后的计算语法<?php
$capture_field_vals1="";
if(isset($_POST['btn']))
{
foreach($_POST['stockin'] as $key => $text_field){
$capture_field_vals1 .= $text_field;
}
echo $capture_field_vals1;
$num1 = $_POST['stock[]'];
$num2 = $_POST['$capture_field_vals1'];
$num3 = $num1 + $num2;
echo $num3;
}
?>
答案 0 :(得分:0)
“[]”表示数组,此时您可能需要向数据库写入多个数据。同样在PHP脚本中,您可以通过var_dump($_POST);
<?php
if( isset($_POST["stock"]) ){
foreach ($_POST["stock"] as $key => $value) {
echo $value."<BR>";
}
}
?>
<form method="post" action="?">
<input type = "text" name = "stock[]" size = "5" value = '1'/>
<input type = "text" name = "stock[]" size = "5" value = '2'/>
<input type="submit">
</form>