Jump to content

Getting ID after submission


Arbitus

Recommended Posts

So I'm working on this forum and I hit a problem.

 

Right now I have 2 tables for posts and topics.

 

I have a topics table which stores the board_id, topic_title, topic_owner, and of course, the topic ID itself.

 

Then I have the posts table which also stores the topic_title, it's own id, users message and so on

 

	// Insert the information into arbi_topics first
$newtopicsql = "INSERT INTO `arbi_topics` (title,board_id,starter_id) 
		  VALUES ('$topictitle','$boardid','$username')" or die (mysql_error());
mysql_query($newtopicsql) or die (mysql_error());

//Insert the information in arbi_posts second
$newpostsql = "INSERT INTO 'arbi_posts' (topic_id,topic_title,message,post_owner)
				VALUES ('$newID','$topictitle','$topicmessage','$username')" or die (mysql_error());

 

In the first query, it is storing some information in the topic table. While the second query is storing the information in the posts table. Some how I need to get the ID from the topics table into a variable so I can store the topic ID into the posts table.

Link to comment
https://forums.phpfreaks.com/topic/136905-getting-id-after-submission/
Share on other sites

I can't figure out how to use it, or store it's value in a variable so I can insert it into the next query.

 

// This is the topic table

$newtopicsql = "INSERT INTO `arbi_topics` (title,board_id,starter_id)

  VALUES ('$topictitle','$boardid','$username')" or die (mysql_error());

mysql_query($newtopicsql) or die (mysql_error());

 

 

 

//I need the ID of what I just entered able to be inserted here in topic_id

$newpostsql = "INSERT INTO 'arbi_posts' (topic_id,topic_title,message,post_owner)

VALUES ('$topicid2','$topictitle','$topicmessage','$username')" or die (mysql_error());

mysql_query($newpostsql) or die (mysql_error());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.