Hello dear Developers,
I am trying to add a string value to a specific cell on my SQL database but its not working somehow, I have tried with CONTACT but its updating all cells, even if I have added WHERE conditions.
Here is the code I am using:
$asset = "Neo";
$space = " "
$sql="UPDATE `open_trades` SET `asset` = '$asset $space;', `laverage` = '$laverage', `live_price` = '$live_price' WHERE `id` = '$trade_id';";
I need $asset
and $space
combined, in this case Neo 
but I am not sure how to implement it, on this way its updating the cell but its adding only $space
, and the cell value its updating to only $space
.
I also tried to combine values via PHP but still adding only $space
.
Thanks and regards.
My Answer:
You can concatenate the string values in your SQL query using the CONCAT function. Here is an updated version of your code:
php
$asset = "Neo";
$space = " ";
$sql = "UPDATE `open_trades` SET `asset` = CONCAT(`asset`, '$space'), `laverage` = '$laverage', `live_price` = '$live_price' WHERE `id` = '$trade_id';";
This will append the value of $space to the existing value of the `asset` column in the `open_trades` table.
Rate this post
3 of 5 based on 8078 votesComments