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. 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? 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. 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? 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. 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
Archived
This topic is now archived and is closed to further replies.