php - Insertion into database -
how query insert row 1 table another? use conventional insert select delete . thing works deleting trade. values not updating in new table. used constants in second table because tables have unmatched columns , problem here?
<?php //if(!isset($trade_id)){ $trade_id= $_get['id']; //} require_once('connect.php'); $mysqli = new mysqli($database_hostname, $database_username, $database_password, $database_name) or exit("error connecting database"); try { // first of all, let's begin transaction $mysqli->autocommit(false); // set of queries; if 1 fails, exception should thrown $mysqli->query("insert `trade_history1` (session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit,dateclose,close, profitandloss) select session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss,'null','null' `opentrades` `trade_id` = " . $trade_id); $mysqli->query("delete `opentrades` `trade_id` = " . $trade_id); // if arrive here, means no exception thrown // i.e. no query has failed, , can commit transaction $mysqli->commit(); $_session['message'] = 'successfully deleted'; } catch (exception $e) { // exception has been thrown // must rollback transaction $_session['message'] = 'unable delete'; $mysqli->rollback(); } // if delete this, $mysqli->close(); // bid price,offer price, size,type, header('location:js.php'); ?>
use following code mysqli_execute();instead of mysqli_query(); $mysqli->execute("insert `trade_history1` (session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit,dateclose,close, profitandloss) select session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss,'null','null' `opentrades` `trade_id` = " . $trade_id); $mysqli->execute("delete `opentrades` `trade_id` = " . $trade_id);
Comments
Post a Comment