我想对 html 文本框中的 php 变量中的值求和,我的 php 代码如下
$total = 0;
$val2 = $_POST['val1'];
$total += val2;
echo "Sum of value is ". $total;
这是我的 HTML:
<form action="add.php" method="post" >
<input type="text" name="val1" />
...
...
最佳答案
使用 session
session_start();
$total = 0;
$val2 = $_POST['val1'];
$_SESSION["total"]+= $val2;
echo "Sum of value is ". $_SESSION["total"];
A session is a way to store information (in variables) to be used across multiple pages
关于php - 在 php 变量中添加 html 文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33937646/