Hi!

I need to know if theres a function that is simmilar to mysql_insert_id function

where it gets the last inserted id

but the thing is my id is not auto increment

i tried doing the select statement but not working

my scenario is:

i am updating a record from one table after inserting a new record in another table

so insert then update in one script.

thanks in advance!

i guess that your scenario is that you are updating 2nd table after inserting in 1st table???
try

mysql_info()

it doesn't matter if your incrementing your id or not, mysql_insert_id() always return the last inserted id

it doesn't matter if your incrementing your id or not, mysql_insert_id() always return the last inserted id

no it returns 0 if column is not auto incremented

no it returns 0 if column is not auto incremented

it's because it is not incremented! did you get my point? because he did not increment his primary id, all his id including his last id is zero

From the manual:
"Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT)."

I've highlighted the important parts:
1. If he is not using an auto increment ID column, then this function returns zero.
2. You have to call this function directly after the INSERT query, otherwise it returns zero.

If the OP is not using an auto incremented ID, he has to query the table with a SELECT to get the highest (most likely last) ID, or any other logic that matches his inserting logic.

Thats the reason why I indicated that my id is not auto increment

cause I know it will return 0 or false

Ive also tried doing select statement after insert then update but not getting any luck

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.