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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:57:12+00:00 2026-05-26T11:57:12+00:00

When a successful register happens there is an Insert into members table. It has

  • 0

When a successful register happens there is an Insert into members table. It has an id filed auto increment.

//Create INSERT query
$qry = "INSERT INTO members(email, passwd) VALUES('$email', '$password')";
$result = mysql_query($qry);

Because I need to save some of the input in another table named companies, I find the total records ( that means the last ID)

//find lastid from members
$lastid = mysql_fetch_array(mysql_query("select count(id) as lastid from members"));
$lastid = $lastid[lastid];

and save it into the table companies.

//Insert lastid to Companies
$insertit = mysql_query("INSERT INTO companies( id, name) VALUES('$lastid', '$cname' )");

This is working successfully but is there a better way of doing this ? I have removed some of the fields to give a better more to the point example.

  • 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-26T11:57:13+00:00Added an answer on May 26, 2026 at 11:57 am

    Assuming members.id is an AUTO_INCREMENT field you can cut a bit out using mysql_insert_id():

    //Create INSERT query
    $qry = "INSERT INTO members(email, passwd) VALUES('$email', '$password')";
    $result = mysql_query($qry);
    
    //find lastid from members
    $lastid = mysql_insert_id();
    
    //Insert lastid to Companies
    $insertit = mysql_query("INSERT INTO companies( id, name) VALUES('$lastid', '$cname' )");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anybody any successful remarks about having a team working via Remote Desktop? In
where can I put a println in order to register a user's successful authentication
As of right now, I have the user register/log in and then if successful,
I want to specify a raw username/password into an SQL query with PHP: function
Im trying to register an event listener for a successful login, so that I
I have an ASP.net Login Control which has a link to CreateUserWizard page(register). When
I m trying to create a new register and login page. I have a
After successful setup on initial launch of MySQL, the page prompted me to set
I've been successful with writing my own SQL access code with a combination of
After a successful start of Tomcat and a few REST calls I get this

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.