onedumbcoder Posted May 28, 2009 Share Posted May 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159985-solved-mysql_insert_id-returns-zero-when-doing-insert-with-not-exists/ Share on other sites More sharing options...
roopurt18 Posted May 29, 2009 Share Posted May 29, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/159985-solved-mysql_insert_id-returns-zero-when-doing-insert-with-not-exists/#findComment-844635 Share on other sites More sharing options...
onedumbcoder Posted May 29, 2009 Author Share Posted May 29, 2009 yes, the query is working fine. I checked the database after each execution. Quote Link to comment https://forums.phpfreaks.com/topic/159985-solved-mysql_insert_id-returns-zero-when-doing-insert-with-not-exists/#findComment-844661 Share on other sites More sharing options...
haku Posted May 29, 2009 Share Posted May 29, 2009 Do you have an auto-increment column in trade_offer? Quote Link to comment https://forums.phpfreaks.com/topic/159985-solved-mysql_insert_id-returns-zero-when-doing-insert-with-not-exists/#findComment-844730 Share on other sites More sharing options...
onedumbcoder Posted May 29, 2009 Author Share Posted May 29, 2009 wow... im so dumb! when i created the table I never set up auto increment Thank you haku and everyone else as well. Quote Link to comment https://forums.phpfreaks.com/topic/159985-solved-mysql_insert_id-returns-zero-when-doing-insert-with-not-exists/#findComment-844761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.