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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:27:27+00:00 2026-06-12T12:27:27+00:00

I have a simple table CREATE TABLE `keys` ( `IDkey` int NOT NULL auto_increment,

  • 0

I have a simple table

CREATE TABLE `keys` (
`IDkey` int NOT NULL auto_increment,
`username` varchar(50) NOT NULL, 
PRIMARY KEY  (`IDkey`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

and give out incrementing integer keys ‘IDkey’ to users as they call in with my webapp. I also store their username in the table.

I have two questions I’m stuck on.

First question: at the moment I am doing the following to give out the key, is there a way to combine this into one query?

INSERT INTO keys VALUES (NULL, '$username');
SELECT IDkey FROM keys WHERE username='$username';

Second Question: the key expires so the same user may return for a new key but this causes a problem because their username is already in the database. Is there a way to write my SELECT query so it returns the most recent record by that user?

  • 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-12T12:27:29+00:00Added an answer on June 12, 2026 at 12:27 pm

    If you’re using PDO, check out PDO::lastInsertId().

    If you’re using mysqli, check out mysqli::$insert_id.

    If you’re using mysql, upgrade your code to use PDO or mysqli. 😉 (But seriously, you can do this with mysql_insert_id()).

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

Sidebar

Related Questions

Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
I have table: CREATE TABLE IF NOT EXISTS `TxtDila` ( `ID` int(11) NOT NULL
I have two tables: CREATE TABLE IF NOT EXISTS treaties( id INT NOT NULL
i have a table: CREATE TABLE `p` ( `id` bigint(20) unsigned NOT NULL, `rtime`
I have a simple table stock_ledger_id INT(10) (Primary) piece_to_bin_id INT(10) quantity INT(11) create_datetime TIMESTAMP
I have the following Table: CREATE TABLE `sal_forwarding` ( `sid` BIGINT(20) UNSIGNED NOT NULL
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple table creating script in Postgres 9.1. I need it to create
I have a simple table in Sybase, let's say it looks as follows: CREATE
I have a very simple table with two columns, but has 4.5M rows. CREATE

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.