Page 1 of 1

Inserting Data into Table [solved]

Posted: Sat Jun 16, 2007 7:25 am
by king spengo
Hi I am attempting to design my own forum, at the moment I am working on adding new topics. There are two tables which I need to insert data into; topics and posts.

I've got the first bit figured out; entering data into the topics table:

Code: Select all

mysql_query("INSERT INTO topics (forum_id, topic_title, topic_desc, topic_poster, topic_time, topic_last_post_id) VALUES ('$forum_id', '$topic_title', '$topic_desc', '$topic_poster', '$topic_time', '$topic_last_post_id')");
In the topics table I have a field called "topic_id" which is set to auto increment and in the posts table I also have a field called "topic_id" which is not auto increment.

Now I need to insert data into the posts table where "topic_id" is equal to the value of "topic_id" in the topics table that has just been inserted.

Basically when I insert my data into the topics table a unique number is generated and I need to know this number so I can add to the posts table.

If anyone can help I'd be most thankful.

Posted: Sat Jun 16, 2007 8:13 am
by feyd

Posted: Sat Jun 16, 2007 8:43 am
by king spengo
Thank you Feyd I'll check that out.

Posted: Sat Jun 16, 2007 9:04 am
by king spengo
Thank you again, problem solved.