Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3324122
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:23:02+00:00 2026-05-17T23:23:02+00:00

Ran into a bit of trouble when trying to insert records into my DB

  • 0

Ran into a bit of trouble when trying to insert records into my DB from my forum

What it does when you create a thread is make an entry into 2 tables. First the forum_threads table with information on the thread title, description, poster, post time, etc. It will use thread_id with AUTO_INTEGER to generate the threads ID.

I then need to get that thread_id from the forum_threads and then put that as the thread_id in the forum_posts table.

I’m not sure if theres anyway I can select a row based on its ID after I just inserted it. Would I just have to select the most recent ID? Would that leave a margin of error? Other thought I had was to select based on user name and post time.

Thoughts?

<?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);
}

?>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:23:02+00:00Added an answer on May 17, 2026 at 11:23 pm

    MySqli_Insert_Id () will return the last auto generated ID. Call this function immediately after you insert your new thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create some HtmlHelper extensions and ran into a bit of a
I ran into a bit of trouble while trying to load an external HTML
Hi :) I've ran into a bit of a trouble. (short-form: whenever the page
I recently ran into major problems inserting records into a SQL Server backend from
I've ran into a problem while trying to test following IRepository based on NHibernate:
I'm writing my own software rasterizer in Java, and I ran into some trouble
Ran into a bit of an issue with some jQuery code, but in essence,
I have ran into a bit of problem. Originally, I have the following input
I've recently ran into a bit of a pain. I've been using the JQuery
I am a bit new to Fluent nHibernate and ran into a scenario with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.