Jump to content

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


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?

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.