Hi Guys, I am inserting values in two tables. After the insert of values in the first table, I want to get the inserted ID(first table) because I need that value in my second table.This is my code but I think it will gives error when there are many values inserted I am right? Or I should use mysql_insert_id()? Is it ok using mysql_insert_id()? Thank you

SELECT max(sampid) as sampid FROM sampinfo

Recommended Answers

All 3 Replies

you should have generated an id for both tables before you insert the data.
because i think querying for max id is not the answer when you have more than 1 user using whatever it is you building.

Member Avatar for diafol

mysql_insert_id used to be the way to do it. Now it.s the pdo or mysqli equivalent.

ok thanx, I'll try it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.