嘗試從我的論壇插入記錄到我的數據庫時遇到了一些麻煩MySQL插入選擇
當您創建線程時,它會對2個表進行輸入。首先是forum_threads表,其中包含主題標題,說明,海報,發佈時間等信息。它將使用帶AUTO_INTEGER的thread_id生成線程ID。
然後,我需要從forum_threads中獲取該thread_id,然後將其作爲thread_id放入forum_posts表中。
我不確定無論如何,我可以根據它的ID選擇一行後我插入它。我只需要選擇最近的ID?這會留下一個錯誤的餘地嗎?我的其他想法是根據用戶名和帖子時間來選擇。
想法?
<?php
if (isset($_POST['submit'])) {
$thread_sql = "
INSERT INTO forum_threads (
user_id,
forum_id,
thread_postdate,
thread_title,
thread_description,
thread_icon
) VALUES (
'$_SESSION[user_id]',
'$_GET[f]',
'$date',
'$_POST[topictitle]',
'$_POST[topicdescription]',
'$_POST[posticon]'
)
";
$thread_query = @mysqli_query ($db_connect, $thread_sql);
$post_sql = "
INSERT INTO forum_posts (
user_id,
thread_id,
post_message,
post_date
) VALUES (
'$_SESSION[user_id]',
'',
'$_POST[content]',
'$date'
)
";
$post_query = @mysqli_query ($db_connect, $post_sql);
}
?>