如何将变量中的值插入数据库(例如$ closedb,$ profitandloss)

时间:2013-08-18 18:59:48

标签: php sql

我只想知道将变量中的值插入DB中的表的正确方法。我这样做是错误的吗?

**$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 WHERE `trade_id` = " . $trade_id);
    **$mysqli-> query("UPDATE trade_history1 set close='{$closedb}' WHERE `trade_id` = " . $trade_id);**
    **$mysqli-> query("UPDATE trade_history1 set profitandloss='{$profitandloss}' WHERE `trade_id` = " . $trade_id);**

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

1 个答案:

答案 0 :(得分:0)

你的意思是这样吗?

$mysqli->query("UPDATE trade_history1 set profitandloss='" . addslashes($profitandloss) . "' WHERE `trade_id` = '" . addslashes($trade_id) . "'");

我没有看到这些变量的任何声明。