我曾尝试使用插入所需表select * from XXX
然后将其删除的方法,但我似乎无法插入我的新表并删除旧表中的那个。
它读取为trade_id
as1,2,3,4
但我似乎无法将其删除。第 4 行出现错误 trade_id 我似乎无法理解为什么它没有定义。
查询有什么问题吗?
删除.php
<?php
// we need to know the student id so that we can delete the right student
$tradeid= $_GET['trade_id'];
// the file that contains your database credentials like username and password
require_once('connect.php');
// see Lecture Webp_Week13_14_Using_PHPandMySQL(updating).pptx Slide 4 aka Step 1
$mysqli = new mysqli($database_hostname, $database_username, $database_password, $database_name) or exit("Error connecting to database");
// Slide 5 aka Step 2
$stmt = $mysqli->multi_query("INSERT INTO `trade_history1` (session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss, dateclose, close)
SELECT session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss, dateclose, close
FROM `opentrades`
WHERE `trade_id` = ?;
DELETE FROM `opentrades` WHERE `trade_id` = ?;
COMMIT;");
// Slide 6 aka Step 3 the bind params must correspond to the ?
$stmt->bind_param("i", $tradeid); // 1 ? so we use i. we use i because id is INT
// Slide 7 aka Step 4
$successfullyDeleted = $stmt->execute();
// Slide 8 aka Step 5
// we won't check the delete result here.
// Slide 9 aka Step 6 and 7
$stmt->close();
$mysqli->close();
// if we successfully delete this, we
if ($successfullyDeleted) {
$_SESSION['message'] = 'Successfully deleted';
} else {
$_SESSION['message'] = 'Unable to delete';
}
header('Location: js.php');
?>
代码的重要部分
JS.php
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['trade_id'] . "</td><td>" . $row['selection'] . "</td><td>" . $row['date'] ."</td><td>" . $row['type'] ."</td><td>" . $row['size'] ."</td><td>" . $row['bidprice'] ."</td><td>" . $row['offerprice'] ."</td><td>" . $row['stoploss'] ."</td><td>" . $row['takeprofit'] ."</td><td>" . $row['profitandloss'] . "</td><td><a href ='delete.php?id=".$row['trade_id']."'>X</a></td></tr>"; //$row['index'] the index here is a field name
}