0

The ThreadID in Thread_Body needs to be the id of Thread_Titles id. How would I go about doing this?

if (isset($_POST['Post_Thread'])) {
    if (empty($_POST['Post_Title'])) {
        echo "No Title No Thread.";
    } else {
        $Sec = mysql_real_escape_string($_GET['sec']);
        mysql_query("INSERT INTO Thread_Titles (Name, Section, Posted, Poster, Updated) VALUES('".cleanPost($_POST['Post_Title'])."', '".$Sec."', '".time()."', '".$ULN->Username."', '".time()."') ") or die(mysql_error()); 
    }
    if (empty($_POST['Post_Body'])) {
        echo "No Body No Thread.";
    } else {
        mysql_query("INSERT INTO Thread_Replies (Body, Posted, Poster, ThreadID) VALUES('".cleanPost($_POST['Post_Body'])."', '".time()."', '".$ULN->Username."', '".$ThreadID."') ") or die(mysql_error()); 
    }
}

This is the code all expect the form.

michi
  • 6,565
  • 4
  • 33
  • 56

1 Answers1

1

Use mysql_insert_id()

mysql_query("INSERT INTO Thread_Titles (Name, Section, Posted, Poster, Updated) VALUES('".cleanPost($_POST['Post_Title'])."', '".$Sec."', '".time()."', '".$ULN->Username."', '".time()."') ") or die(mysql_error());  
$ThreadID = mysql_insert_id();

FYI, you shouldn't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • I have been told this, but yet i still have no idea what you guys are talking about. I am still learning lot and i go by videos and stuff i learn from other people so... Also What will `mysql_insert_id()` do? – user2325910 May 03 '13 at 01:34
  • 1
    Click on all of the links and you will have all of your answers. :) – John Conde May 03 '13 at 01:36
  • Holy crap, that simple? Thank you very much. Also thanks for sharing all that other stuff I will look into it right now. – user2325910 May 03 '13 at 01:40