I get an error when running this php code which going to add value to table 1 based on table 2 value where table 3 value equal to 0
MY TABLE
------------------------------
id| table 1| table 2 | table 3|
-------------------------------
01| 100 | 10 | 0 |
PHP CODE
<?php
$servername = "localhost";
$username = "myuser";
$password = "mypass";
$dbname = "lol";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "UPDATE table table1 = table1 + table2 WHERE table 3 = 0";
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
It said that I have error in my sql syntax
Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= table1 + table2 WHERE table3 = 0' at line 1
How to achieve this with the correct sql syntax?