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 7985989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:43:04+00:00 2026-06-04T11:43:04+00:00

I have a many-to-many MySQL database with three tables entry, tag, and entry_tag. entry

  • 0

I have a many-to-many MySQL database with three tables entry, tag, and entry_tag.
entry table has id INT AUTO_INCREMENT PRIMARY KEY, title TEXT and entry TEXT columns
tag table has id INT AUTO_INCREMENT PRMARY KEY and tag VARCHAR(15) columns
entry_tag is a mapping tables between entry and tag, and has entry_id INT and tag_id INT, entry_id and tag_id creates PRIMARY KEY.

Now, I would like to INSERT entry.title and entry.entry and related tags tag.tag to the database and respective tables. I would also like to INSERT appropriate mapping information into entry_tag table. Could anyone tell me how can I possible do it? I am using PHP. How can I get the entry.id and tag.id and link them together in the mapping table?

I have:

$sql_query = "INSERT INTO entry SET
    title = '$title',
    entry = '$entry'";

if (!mysqli_query($link, $sql_query)) {
    $error = 'Error adding submitted entry.';
    include 'includes/error.html.php';
    exit();
}

$sql_query = "INSERT INTO tag SET
    tag = '$tag'";

if (!mysqli_query($link, $sql_query)) {
    $error = 'Error adding submitted entry.';
    include 'includes/error.html.php';
    exit();
}

Now, I would like to perform:

$sql_query = "INSERT INTO entry_tag SET
    entry_id = '$entry.id',
    tag_id = '$tag.id'";

But I stuck on getting the right $entry.id and $tag.id.

  • 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-06-04T11:43:05+00:00Added an answer on June 4, 2026 at 11:43 am

    Use mysql_insert_id() to capture the ID of the last insert

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

Sidebar

Related Questions

I have a MySQL database in which table A has a one-to-many relation to
Here's some background info. I have three MySQL tables (all InnoDB). The first table
I have a MySQL database that contains many tables, some of them created dynamically
I have a legacy mysql database and there's this table which has a few
I have a mySQL database with a number of tables with many fields. Is
I have a MySQL database which has 10 tables in it. The database structure
I have a MySQL table that holds many entries with repeated IDs (for various
Hi I have one big problem with one MYSQL search. My database TABLE looks
I have a MySQL database with a lot of tables, and I have two
let's say I have three tables (MySQL), one for users, one for tags and

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.