Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将数据库中的值和文本框中的输入值相加_Php_Mysql - Fatal编程技术网

Php 如何将数据库中的值和文本框中的输入值相加

Php 如何将数据库中的值和文本框中的输入值相加,php,mysql,Php,Mysql,这是我的问题:我从数据库中获取股票的价值,并在文本框中输入一个值,问题是当我试图计算时,系统没有识别或说未定义的指数:股票 以下是从值到计算的语法: <td><input type = "text" name = "stock[]" size = "5" value = '<?php echo $row['stock']; ?>' disabled></td> <td><input type = 'text' name = '

这是我的问题:我从数据库中获取股票的价值,并在文本框中输入一个值,问题是当我试图计算时,系统没有识别或说未定义的指数:股票

以下是从值到计算的语法:

<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脚本中,您可以通过
var\u dump($\u post)观察传入的post



你想在这里做什么:
$num2=$\u POST['$capture\u field\u vals1']?我想添加我在库存中输入的值,我试图声明它是否可行。。。但最终不是你用javascript添加了一个以上的值吗?如果没有,则将
更改为
,在PHP中,
$\u POST['stock']
是表单中的值……您可以使用少量JavaScript添加值Show我会添加显示值和输入值吗?这是我的问题,我试图解决,但它不起作用我只是改变了一点以前的帖子。
<?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;
}
?>
<?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>