$add_topic_sql = "insert into forum_topics(topic_title,topic_create_time,topic_owner) values('$topic_title',now(),'$topic_owner')"; $add_topic_result = mysqli_query($conn3,$add_topic_sql);
$topic_id = mysqli_insert_id($conn3);
$add_post_sql = "insert into forum_posts(topic_id,post_text,post_create_time,post_owner) values('$topic_id','$post_text',now(),'$topic_owner')"; $add_post_result = mysqli_query($conn3,$add_post_sql);
mysqli_close($conn3);
$display_block = "
".$_POST['topic_title']."已创建成功!
"; ?>
增加新主题
增加新主题
topiclist.php(论坛主题列表)
/** * Created by PhpStorm. */ include_once ('include3.php'); doDB(); $get_topics_sql = "select topic_id,topic_title, DATE_FORMAT(topic_create_time,'%b %e %Y at %r') AS fmt_topic_create_time,topic_owner from forum_topics order by topic_create_time desc"; $get_topics_res = mysqli_query($conn3,$get_topics_sql) or die(mysqli_error($conn3));
$get_num_posts_sql = "select count(post_id) as post_count from forum_posts where topic_id=$topic_id"; $get_num_posts_res = mysqli_query($conn3,$get_num_posts_sql) or die(mysqli_error($conn3));
$get_posts_sql = "select post_id,post_text, DATE_FORMAT(post_create_time,'%b %e %Y %r') as fmt_post_create_time, post_owner from forum_posts where topic_id=$topic_id order by post_create_time asc"; $get_post_res = mysqli_query($conn3,$get_posts_sql) or die(mysqli_error($conn3));
$post_id = mysqli_real_escape_string($conn3, $_GET['post_id']); $sql = "select ft.topic_id,ft.topic_title from forum_posts as fp LEFT JOIN forum_topics as ft ON fp.topic_id = ft.topic_id where fp.post_id=$post_id";
INSERT INTO `forum_posts` (`post_id`, `topic_id`, `post_text`, `post_create_time`, `post_owner`) VALUES (2, 2, 'I\'m interested in knowing how people got started in technology -- did you thinker with household electronics? did you learn about it in school? did you parents buy you a computer and tell you to have at it.', '2019-06-01 09:09:38', 'jane@doe.com'), (6, 4, '如题,这是一个简易的论坛,用于测试的。\r\n', '2019-06-01 17:00:46', 'abc@163.com'), (7, 4, '这是一个测试的回复。', '2019-06-01 17:17:29', 'bat@baba.com');
INSERT INTO `forum_topics` (`topic_id`, `topic_title`, `topic_create_time`, `topic_owner`) VALUES (2, 'How did you get statrted with technology?', '2019-06-01 09:09:38', 'jane@doe.com'), (4, '这是一个简易的论坛,用于测试。', '2019-06-01 17:00:46', 'abc@163.com');