[SOLVED] how to sum up a specific cell and replace it with the new one php


I got a PHP code like this

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);




$sql="SELECT Current_Balance FROM users WHERE id='".$ID."'";
$result = mysqli_query($conn, $sql);


 $sum +=  (int)$sql + (int)$y;

echo "New Balance is: ",$sum;

I want to take a specific number from my cell and sum it up with a user’s input number and then replace the cell’s specific number with the new one. Any idea why this is not working?


Your trying to convert your text query into an int.

$sum +=  (int)$sql + (int)$y;


$result = mysqli_query($conn, $sql);

Should be

$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;

Answered By – Anthony Dewstow

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *