如何汇总特定单元格并将其替换为新单元格 php
how to sum up a specific cell and replace it with the new one php
我得到了这样的 PHP 代码
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$ID=$_POST["ID"];
$Deposit=$_POST["Deposit"];
$sum=0;
$sql="SELECT Current_Balance FROM users WHERE id='".$ID."'";
$result = mysqli_query($conn, $sql);
$y=$Deposit;
$sum += (int)$sql + (int)$y;
echo "New Balance is: ",$sum;
我想从我的单元格中取出一个特定的数字并将其与用户输入的数字相加,然后用新的数字替换单元格的特定数字。知道为什么这不起作用吗?
您正在尝试将文本查询转换为整数。
$sum += (int)$sql + (int)$y;
你的
$result = mysqli_query($conn, $sql);
应该是
$query = mysqli_query($conn, $sql); //asks the question
$result= mysqli_fetch_assoc($conn,$query);//gets the answer
$sum += $result['Current_Balance'] + (int)$y;
echo "New Balance is: ".$sum;
我得到了这样的 PHP 代码
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$ID=$_POST["ID"];
$Deposit=$_POST["Deposit"];
$sum=0;
$sql="SELECT Current_Balance FROM users WHERE id='".$ID."'";
$result = mysqli_query($conn, $sql);
$y=$Deposit;
$sum += (int)$sql + (int)$y;
echo "New Balance is: ",$sum;
我想从我的单元格中取出一个特定的数字并将其与用户输入的数字相加,然后用新的数字替换单元格的特定数字。知道为什么这不起作用吗?
您正在尝试将文本查询转换为整数。
$sum += (int)$sql + (int)$y;
你的
$result = mysqli_query($conn, $sql);
应该是
$query = mysqli_query($conn, $sql); //asks the question
$result= mysqli_fetch_assoc($conn,$query);//gets the answer
$sum += $result['Current_Balance'] + (int)$y;
echo "New Balance is: ".$sum;