Forum Moderators: coopster
I have two tables, a 'users' table and a 'log' table which is used to store all user activity such as login date and times. When the user is registered, I execute an 'INSERT' SQL statement and a user_id is generated automatically for that user, since the field user_id is set to auto_increment.
Now, when the user registers, I also need to add the first log to the 'log' table from the same PHP registration script. The 'log' table has these fields: 'log_id' (auto generated), 'user_id' (a user id) and 'msg' (with the actual log as a string). I need to add the folowing record:
INSERT INTO log (user_id, msg) VALUES ('xx', 'Registered at $datetime');
I need to get the auto generated user_id from the previous INSERT command to replace the 'xx'
I tried mysql_fetch_array after executing the insert command but I was not successful. afaik, ASP lets you to do this. Is there a way to do this with PHP without having to execute another SQL statement to fetch the last entered record?
mysql_insert_id on the other hand
Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
so it knows which query/thread it is working with and will not make mistakes.
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]