gpt4 book ai didi

php - 设置后立即在同一页面获取 ID

转载 作者:行者123 更新时间:2023-11-29 13:53:10 27 4
gpt4 key购买 nike

Thread_Body中的ThreadID需要是Thread_Titles id的id。我该如何去做呢?

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());
}
}

这是所有期望的形式的代码。

最佳答案

使用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();

仅供引用,you shouldn't use mysql_* functions in new code 。它们不再维护and are officially deprecated 。请参阅red box ?了解 prepared statements相反,并使用 PDO ,或MySQLi -this article将帮助您决定哪个。如果您选择 PDO,here is a good tutorial .

关于php - 设置后立即在同一页面获取 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16350248/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com