Jump to content

[SOLVED] mysql_insert_id returns zero when doing insert with NOT EXISTS


onedumbcoder

Recommended Posts

i am having an issue with mysql_insert_id() function, it works unless i use a insert query with a NOT EXISTS in it.

 

here is the query i am executing

 

INSERT INTO trade_offer(trade_listing_id, offer) SELECT '$postid','$postoffer' FROM trade_offer WHERE NOT EXISTS (SELECT id FROM trade_offer WHERE trade_listing_id='$postid' AND status='0' ORDER BY date_stamp LIMIT 1) LIMIT 1

 

 

when i echo mysql_insert_id() after this, it always returns zero.

 

I have used mysql_insert_id before and it works. the only difference here is that i have an insert with a not exists in it.

RETURN VALUES

The ID generated for an AUTO_INCREMENT column by the previous INSERT query on success, 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established.

 

Are you sure your query is inserting anything?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.