howdy all,
im trying to configure a php forum to work with a portal system I built. The problem I am having is when a user replies to a post, it inserts the post data into the posts table then it will grab the last autonumber id, which is the postifd, by using the mysql_insert_id function and insert it into other tables such as the posts_text table. The problem is, and I don't know how this happened, but the autonumber will generate a number like 6, but the mysql_insert_id will return a number like 2453. Maybe Im just missing something but I know how I can get around the problem - just by quering the database for the newest postid and get it that way, but it isnt as efficient. Any help would be greatly appreciated. Thanks
mysql_insert_id
Moderator: General Moderators
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
Is the postifd field BIGINT? If so then that may be the problem. Try using the SQL function LAST_INSERT_ID() to set the ID based off of your postifd. Insert the posts row, and then use LAST_INSERT_ID() to set the id for the new rows in the other table, ex:
Code: Select all
INSERT INTO posts_text (id, otherfield) VALUES (LAST_INSERT_ID(), 'foo')