Inserting Data into Table [solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
king spengo
Forum Newbie
Posts: 8
Joined: Sat Jun 16, 2007 7:13 am

Inserting Data into Table [solved]

Post 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.
Last edited by king spengo on Mon Apr 13, 2009 1:19 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

king spengo
Forum Newbie
Posts: 8
Joined: Sat Jun 16, 2007 7:13 am

Post by king spengo »

Thank you Feyd I'll check that out.
king spengo
Forum Newbie
Posts: 8
Joined: Sat Jun 16, 2007 7:13 am

Post by king spengo »

Thank you again, problem solved.
Post Reply