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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:24:52+00:00 2026-06-12T21:24:52+00:00

$db->query(INSERT into `users` (username, password, email) VALUES (‘$username’, ‘$hashpassword’, ‘$email’)); $userid = mysqli_insert_id($db->link); $db->query(INSERT

  • 0
$db->query("INSERT into `users` (username, password, email)
    VALUES ('$username', '$hashpassword', '$email')");

$userid = mysqli_insert_id($db->link);

$db->query("INSERT into `users logins` (userid, token, ip)
    VALUES ('$userid', '$token', '$ip')");

The above is old code. The below is my new:

$db->query("BEGIN TRANSACTION;
INSERT into `users` (username, password, email)
VALUES ('$username', '$hashpassword', '$email');

[here I need to get the row ID of the above insert]

INSERT into `users logins` (userid, token, ip)
VALUES ('$userid', '$token', '$ip')
COMMIT;");

How can I grab the first insert row ID and use it for the second insert?

  • 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-12T21:24:53+00:00Added an answer on June 12, 2026 at 9:24 pm

    use LAST_INSERT_ID()

    ...
    
    INSERT into `users logins` (userid, token, ip)
    VALUES (LAST_INSERT_ID(), '$token', '$ip')
    
    ...
    

    or how about creating Stored Procedure

    DELIMITER $$
    CREATE Procedure InsertRecord
    (
        IN _userName VARCHAR(50),
        IN _passWord VARCHAR(50),
        IN _email VARCHAR(50),  
        IN _token VARCHAR(50),
        IN _ip VARCHAR(50)
    )
    BEGIN
        DECLARE Last_ID INT;
    
        INSERT into `users` (username, password, email)
        VALUES (_userName, _passWord, _email);
    
        SET Last_ID = LAST_INSERT_ID();
    
        INSERT into `users logins` (userid, token, ip)
        VALUES (LAST_INSERT_ID(), _token, _ip);
    
        SELECT Last_ID;
    END $$
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the query: INSERT INTO `users` (username, password, email) VALUES ('testu', 'testp', 'teste')
Can naybody tell me what this means INSERT INTO users (first_name,last_name,email,username,password,privilege) VALUES ('s',1,1,1,1,1); but
$pass = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6); $insert = mysql_query(INSERT INTO users(username, password) VALUES( '.$username.', '.md5($pass).')); or $salt
$sql = INSERT INTO $table_name VALUES ('$_POST[firstname]', '$_POST[lastname]', '$_POST[username]', password('$_POST[password]'), 'Users', '', '', '$pchange',
The following query was successful when I used in mysql INSERT INTO user(`dev_id`,`email`) VALUES('123','456@gmail.com');
I have the following query: INSERT INTO table (a, b, c) VALUES (NOW(), NOW()
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
My database table has columns email, username and password. I'm trying to insert these
I want to specify a raw username/password into an SQL query with PHP: function
I want to insert the values ('testu', 'testp', 'testname', 'testsur', 'testemail') into [dbo].[users] I'm

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.