如何使用插入 ID 插入到另一个 table?

How can I insert to another table using the insert id?

我遇到了这样的问题,我无法获取父级的 ID table。

table_name : transaction_tbl

- transaction_id
-file_name
-file_path
-description

table_name : transaction_details
-details_id
-transaction_id
- details 

这是我要插入的代码:

$sql = "INSERT INTO transaction_tbl (`file_name`,`file_path`,`description`) VALUE('$file_name','$file_path','$description') " ;

$query = $conn->query($sql);
$transaction_id = mysqli_insert_id($conn);
if ($query === True ){
      $sql = "INSERT INTO transaction_details (`transaction_id`,`details`) VALUES ($transaction_id,$details) ";
}else {
      trigger_error('Wrong SQL: ' . $sql . 'Error: ' . $conn->error, E_USER_ERROR);
}

现在我可以插入 transaction_tbl 但不能插入 transaction_details。我应该怎么办?有人可以帮助我吗?

if condition里面添加$query = $conn->query($sql);如下

if ($query === True ){
      $sql = "INSERT INTO transaction_details (`transaction_id`,`details`) VALUES ($transaction_id,$details) ";
      $query = $conn->query($sql);
}
else {
          trigger_error('Wrong SQL: ' . $sql . 'Error: ' . $conn->error, E_USER_ERROR);
}