nigel
nigel

Reputation: 101

SQL Updating with variable not working

Okay the code below simply means i am moving rows into other table using the insert select delete method. But the thing about this question is that i have 2 variables i want to move also, they are $profittext and $closedb which are being defined in another php file. Thus , I used an update function to insert it inside the DB table. The type of this 2 variables are 19,2 decimal and 10,5 decimal respectively. The output is that the moving of row works , but the update function is not working and no value is being put in. Does any one know how to solve the problem??

   $mysqli->query("INSERT INTO `trade_history1` (user_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit,dateclose,close,profitandloss)
    SELECT user_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, 'null','null','null'
    FROM `opentrades`
    WHERE `trade_id` = " . $trade_id);

    $mysqli-> query("UPDATE `trade_history1` SET `dateclose` = CURRENT_TIMESTAMP,
                                                 `close` = '{$closedb}',
                                                 `profitandloss` = '{$profittext}'
                                                WHERE `trade_id`= '$trade_id'");

    $mysqli->query("DELETE FROM `opentrades` WHERE `trade_id` = '$trade_id'");

Upvotes: 2

Views: 77

Answers (1)

Jay
Jay

Reputation: 3393

use this:

$mysqli->query("INSERT INTO `trade_history1` (user_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit,dateclose,close,profitandloss) SELECT user_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, 'null','null','null'
FROM `opentrades` WHERE `trade_id` = '".$trade_id."'");
$mysqli-> query("UPDATE `trade_history1` SET `dateclose` = CURRENT_TIMESTAMP, `close` = '".$closedb."', `profitandloss` = '".$profittext."' WHERE `trade_id`= '".$trade_id."'");
$mysqli->query("DELETE FROM `opentrades` WHERE `trade_id` = '".$trade_id."'");

Upvotes: 2

Related Questions