php - Get ID right after it's set, on same page -
the threadid in thread_body needs id of thread_titles id. how go 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 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 thread_replies (body, posted, poster, threadid) values('".cleanpost($_post['post_body'])."', '".time()."', '".$uln->username."', '".$threadid."') ") or die(mysql_error()); } }
this code expect form.
mysql_query("insert 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. no longer maintained and officially deprecated. see red box? learn prepared statements instead, , use pdo or mysqli - this article decide which. if choose pdo, here tutorial.
Comments
Post a Comment