1

如何获取主题 ID?所以我可以在用户发布后将他重定向到他的主题?如果我切换它,那么我无法在帖子中插入 topic_id。唔。

$stmt = $db->prepare("INSERT INTO topics (subject, posted, first_post_id, last_post, last_post_id, forum_id) 
VALUES (:subject,:posted,:first_post_id,:last_post,:last_post_id,:forum_id)");
$stmt->execute(array(':subject'=>$subject,':posted'=>time(),':first_post_id'=>$cid,':last_post'=>time(),':last_post_id'=>$cid,':forum_id'=>$f));


$stmt = $db->prepare("INSERT INTO posts (poster_id, poster_ip, message, posted, topic_id) 
 VALUES (:poster_id,:poster_ip,:message,:posted,:topic_id)");
$stmt->execute(array(':poster_id'=>$cid,':poster_ip'=>$_SERVER['REMOTE_ADDR'],':message'=>$message,':posted'=>time(),':topic_id'=>$db->lastInsertId()));




header("Location: /thread/".$db->lastInsertId()); // This will get the post ID not topic ID that i want it to
4

1 回答 1

0

使用临时变量:

$stmt = $db->prepare(/* FIRST QUERY */);
$stmt->execute();

$temp = $db->lastInsertId();

$stmt = $db->prepare(/* SECOND QUERY */);
$stmt->execute();

header("Location: /thread/".$temp);
于 2013-06-08T21:44:41.130 回答