I'm using mysqli on PHP to run a query that sums a value to an existing value as follows. I've simplified the query for clarity, normally I use variables for the different values. Obviously the OpenDBConnection is a function that I wrote myself and works perfectly elsewhere in the same script.
$sql="update TBL_Stock set STOCK_Cost = STOCK_Cost + 9 WHERE PO_ID='PO.16.030128'";
$con = OpenDBConnection();
$con->query($sql);
Now, when I execute the query directly in MySQL (using MySQL Workbench) it works perfectly, and 9 is added to the current value of STOCK_Cost. However, on PHP nothing happens, and 9 isn't added to STOCK_Cost.
The strange thing is that the following php bit DOES work:
$sql="update TBL_Stock set STOCK_Cost = 9 WHERE PO_ID='PO.16.030128'";
$con = OpenDBConnection();
$con->query($sql);
Obviously it doesn't do what I want the code to do, but in the last script the value of STOCK_Cost is set to 9.
So just adding changing the last bit to STOCK_Cost = Stock_Cost + 9 ... and it stops working. Any idea what's going on?
STOCK_Cost = Stock_Cost + 9you are not putting correct column name. it should beSTOCK_Cost = STOCK_Cost + 9and your final query will be :-$sql="update TBL_Stock set STOCK_Cost = STOCK_Cost + 9 WHERE PO_ID='PO.16.030128'";$con->queryreturntrueor `false? Have you checked for errors, php.net/manual/en/mysqli.error.php?SET STOCK_Cost = 9query from PHP is actually working, and that the9you're seeing isn't from the test run in MySQL Workbench. I recommend you run a test that sets the value to something unique, and then check the results. (We're assuming that theOpenDBConnectionfunction is performing the necessary checks to verify that the connection is valid.)