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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:05:51+00:00 2026-06-11T23:05:51+00:00

Heres the scenario: I am supposed to make a small site where user can

  • 0

Heres the scenario:
I am supposed to make a small site where user can register, I am using a table named users with fields

userid int unsigned auto_increment,
name varchar(50),
gender enum('m','f'),
time datetime,
joiningyear int unsigned,
primary key (userid)

When I insert a new user I am also supposed to log him in by saving an encrypted form of his userid as a cookie. The problem is this, if userid is already used, it is auto incremented by 1, as is obvious. I would like to recieve this new value as an output of my insert query, without adding another query that fetches it, this will makes things easy.

Currently I am using two seperate queries one checking if randomly chosen userid is already taken and second inserting the entry.
Insert into users(......) values(...)

Is there a way to achieve this with one query?

  • 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-11T23:05:53+00:00Added an answer on June 11, 2026 at 11:05 pm

    Depending on your MySql adapter you can use:

    mysqli_insert_id or PDO::lastInsertId. There is also mysql_insert_id but described with:

    Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

    If you are using any framework, it should support returning last inserted id.

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

Sidebar

Related Questions

Here's the scenario. When a user's login info is submitted, activityIndicator view is shown.
Here's the scenario. I'm using a url rewriter that allows me to specify patterns
Here's the scenario: if this is a user's first time logging into my web
I'm still a learning user of SQL-SERVER2005. Here is my table structure CREATE TABLE
I am trying to make a look up table. Here is the pretext: Suppose,
Here's my scenario. User selects a document in my software and my software extracts
Here is my scenario: I have table A, that has 4 rows (id, col1,
Here is the scenario: -I made a lot of small and big modifications to
I need to instatiate a C# type dynamically, using reflection. Here is my scenario:
I have a scenario where the models look like create_table :users do |t| t.string

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.