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

  • SEARCH
  • Home
  • 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 8438323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:40:56+00:00 2026-06-10T07:40:56+00:00

I have this table for users that stores their usernames and other data, thats

  • 0

I have this table for users that stores their usernames and other data, thats done like this (stripped down):

 CREATE TABLE `prod_users` (
        `p_user_id` INT(11) NOT NULL AUTO_INCREMENT,
        `p_user_name` VARCHAR(200) NOT NULL DEFAULT ''
            `p_comp_name` VARCHAR(300) NOT NULL DEFAULT '',
        PRIMARY KEY (`p_user_id`)
    )
    COLLATE='utf8_general_ci'
    ENGINE=MyISAM

Each time a user signs up, he’ll provide a company name as well.

There’s another table called prod_profiles, which stores profile details like phone nos. fax nos. etc.

CREATE TABLE `prod_profiles` (
        `pf_gen_id` INT(11) NOT NULL AUTO_INCREMENT,
            `pf_user_id` INT(11) NOT NULL DEFAULT '0',
        `pf_user_name` VARCHAR(200) NOT NULL DEFAULT ''
            `pf_comp_name` VARCHAR(300) NOT NULL DEFAULT '',
        PRIMARY KEY (`pf_gen_id`)
    )
    COLLATE='utf8_general_ci'
    ENGINE=MyISAM

When a new user signs up and his details are added to prod_users, is it possible to automatically add his new user_id, user_name and comp_name details to prod_profile using MySql itself? Since each user will have a new p_user_id and we wont know it, it’ll be difficult using php. Can this be achieved inside MySql itself without any problems?

  • 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-10T07:40:57+00:00Added an answer on June 10, 2026 at 7:40 am

    It isn’t difficult using PHP, since you have the LAST_INSERT_ID() available for use, be it via mysql_insert_id() or mysqli::$insert_id, PDO::lastInsertId() or whatever your API provides. As long as you call the two INSERT statements in immediate succession on the same script (it is connection dependent), MySQL will supply the correct p_user_id.

    However, you can use an AFTER INSERT trigger to force MySQL to create the new row automatically:

    CREATE TRIGGER build_profile AFTER INSERT ON prod_users
    FOR EACH ROW
    BEGIN
      INSERT INTO prod_profiles 
        (pf_user_id, pf_user_name, pf_comp_name) 
        VALUES (NEW.p_user_id, NEW.p_user_name, NEW.p_comp_name)
    END
    

    Review the MySQL CREATE TRIGGER syntax reference for full details and options.

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

Sidebar

Related Questions

I have a schema design that looks like this: Table: User Row Column Family
I have a 'users' SQL table structure like this (the ID is randomly generated
I have a 'users' SQL table structure like this (the ID is randomly generated,
I have a table which looks like this: mysql> SHOW COLUMNS FROM Users; +------------+--------------+------+-----+---------+----------------+
Lets say I have a MySQL table, Users, like this - ----------------------------------------- ID |
I have a table that stores scores from users of my game - what
I have a couple of tables which look like this Table 1 user_id |
I have a user table like this FIRSTNAME | LASTNAME | ID | --------------------------------
The table's schema is pretty simple. I have a child table that stores a
I have a webapp I'm making that stores user information, and their preferences regarding

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.