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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:18:53+00:00 2026-06-13T11:18:53+00:00

I’m normalizing my database, to I’m trying to set the value of a field

  • 0

I’m normalizing my database, to I’m trying to set the value of a field the same as the ID for that row so I can join tables.

I tried using LAST_INSERT_ID(), but it doesn’t work. I don’t get a error, but I only get zeros.

INSERT INTO `eleves` (`user_id`, 
`first_name`, `last_name`, 
`username`, `groupe`, 
`password`, `courriel`, 
`active`, `auteur`, 
`citations`, `absurde`, 
`vocabulaire`,  `analyse`, 
`themes`, `personnages`) 
VALUES (NULL, 
'Jane', 'Doe', 
'janedoe', '400', 
'password', 'jane@doe.com', 
'1', LAST_INSERT_ID(), 
LAST_INSERT_ID(), LAST_INSERT_ID(), 
LAST_INSERT_ID(), LAST_INSERT_ID(), 
LAST_INSERT_ID(), LAST_INSERT_ID());

Thanks!

  • 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-13T11:18:54+00:00Added an answer on June 13, 2026 at 11:18 am

    It seems, during your MySQL session there happened no auto generated id was inserted. And hence for the fields for which you want to fill last_insert_id() must be a zero but not an empty(NULL?, SPACE?).

    Try to define a primary key with auto increment in your table and let your generate a new record. And see what happens !

    See the following example:

    $ mysql -u ravi -p test
    Enter password: ********
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2 to server version: 5.0.22-community-nt
    
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    
    mysql> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    |                0 |
    +------------------+
    1 row in set (0.00 sec)
    
    mysql> create table eleves( user_id int not null auto_increment primary key, username varchar(10), auteur int, citations int, absurde int );
    Query OK, 0 rows affected (0.06 sec)
    
    mysql> insert into eleves( username, auteur, citations, absurde )
        -> values( 'janedoe1', last_insert_id(), last_insert_id(), last_insert_id() );
    Query OK, 1 row affected (0.03 sec)
    
    mysql> select * from eleves;
    +---------+----------+--------+-----------+---------+
    | user_id | username | auteur | citations | absurde |
    +---------+----------+--------+-----------+---------+
    |       1 | janedoe1 |      0 |         0 |       0 |
    +---------+----------+--------+-----------+---------+
    1 row in set (0.00 sec)
    
    mysql> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    |                1 |
    +------------------+
    1 row in set (0.00 sec)
    
    mysql> insert into eleves( username, auteur, citations, absurde )
        -> values( 'janedoe2', last_insert_id(), last_insert_id(), last_insert_id() );
    Query OK, 1 row affected (0.01 sec)
    
    mysql> select * from eleves;
    +---------+----------+--------+-----------+---------+
    | user_id | username | auteur | citations | absurde |
    +---------+----------+--------+-----------+---------+
    |       1 | janedoe1 |      0 |         0 |       0 |
    |       2 | janedoe2 |      1 |         1 |       1 |
    +---------+----------+--------+-----------+---------+
    2 rows in set (0.00 sec)
    
    mysql> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    |                2 |
    +------------------+
    1 row in set (0.00 sec)
    
    mysql>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace

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.