PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 20, 2022

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

 April 20, 2022     connection, mysql, performance, php, sum     No comments   

Issue

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?


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;


Answered By - Anthony Dewstow
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing