Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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);
}

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your trying to convert your text query into an int.

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

Your

$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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading