CREATE PROCEDURE AddTopic($fid smallint, $author char(15), $subject char(80), $message mediumtext)
BEGIN
    DECLARE $authorid mediumint;
    SELECT MAX(uid) INTO $authorid FROM bbs_members WHERE username = &author; -- 这句注释掉, 就不会出错, 不明白这句怎么错了?
    DECLARE $postime int;
    SELECT MAX(dateline) INTO $postime FROM bbs_posts;
    IF $postime IS NULL THEN
       SET $postime = 0;
    END IF;
    
    INSERT INTO bbs_threads (fid, subject, author, authorid, dateline, lastpost) VALUES ($fid, $subject, $author, $authorid, $postime, $postime);
    UPDATE bbs_forums SET threads = threads + 1 WHERE fid = $fid;
    INSERT INTO bbs_posts (fid, tid, subject, author, authorid, message, dateline) VALUES ($fid, last_insert_id(), $subject, $author, $authorid, $message, $postime);
    UPDATE bbs_forums SET posts = posts + 1 WHERE fid = $fid;
END;