If you're using MySQL you can use the function mysql_insert_id. This function returns the id of the last insert query executed on the last link opened by mysql_connect(). Note: Your topic_id column needs to be auto incrementing for this function to retrieve it's value.
Here's an example:
Code:
$subject = 'Whatever';
$poster = 'Whoever';
// add the topic
mysql_query("INSERT INTO forums_topics (topic_subject, topic_poster) VALUES('".$subject."','".$poster."')");
$topicid = mysql_insert_id();
mysql_query("INSERT INTO forums_posts (topic_id) VALUES('".$topicid."')");
// if you wanted the value of the auto increment column post_id, you could use mysql_insert_id() again.
Bookmarks