Jump to content

Recommended Posts

Hi all,

 

I need your advise for inserting data into database.

 

To understand the concept could you just help me on this made up example please :

 

such as there are ID(Primary), firstname, surname columns and I want to insert fistname data first then surname data second in different points.

 

INSERT INTO Member(firstname) VALUES ('Max');

 

INSERT INTO Member(surname) VALUES('Power');

 

The data will be inserted in two different rows. So my question is how can I use the automatically generated ID number to insert this values into the same row in two different points. I don't does make sense or not, it is just a example that I made up. Could you help me on this please? Thank you.

Link to comment
https://forums.phpfreaks.com/topic/128345-insert-with-where-condition/
Share on other sites

Pretty much.  You can get the ID as the row is created as well.  How long after you create the Firstname are you looking to set the Surname?  Same script or different?  If you wait too long and you get more than 1 firstname that is the same, you're looking at some problems you'll have to figure out.

Either

INSERT INTO member (firstname, surname) VALUES ('Max', 'Power')

 

or

INSERT INTO Member(firstname) VALUES ('Max');

UPDATE Member SET surname='Power' WHERE id = LAST_INSERT_ID();

 

Note that LAST_INSERT_ID is only available until the current mysql connection is closed

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.