0
//create and issue the first query
    $add_topic_sql = "INSERT INTO forum_topics (topic_title, topic_create_time, topic_owner) VALUES ('$_POST[topic_title]',now(),'$_POST[topic_owner]')";
	$add_topic_res = mysql_query($conn, $add_topic_sql)
	or die(mysql_error($conn));
			//get the id of the last query
			$topic_id = mysql_insert_id($mysql);

Edited by Ezzaral: Fixed code tags.

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by network18
0

What is the problem?

One thing that you could do to make the code better is instead of using the POST array in the actual query, you could clean it up and store it in another variable first, something like:

$topic_owner = mysqli_real_escape_string($conn, trim($_POST['topic_owner']));
0
//create and issue the first query
    $add_topic_sql = "INSERT INTO forum_topics (topic_title, topic_create_time, topic_owner) VALUES ('$_POST[topic_title]',now(),'$_POST[topic_owner]')";
	$add_topic_res = mysql_query($conn, $add_topic_sql)
	or die(mysql_error($conn));
			//get the id of the last query
			$topic_id = mysql_insert_id($mysql);

You messed up with parameters of the mysql_query(), it should have been -

mysql_query($add_topic_sql, $conn)
0
$topic_id = mysql_insert_id($mysql);

is wrong too.mysql_insert_id() expects the MySQL link parameter.
It should have been like -

$topic_id = mysql_insert_id($conn);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.