向论坛添加新主题


Add a new topic to a forum

我正在尝试创建只允许登录用户在论坛中创建新主题的代码。

我有一个论坛。php, topic_process.php, reply_process.php页面。论坛已经设置好了,并且只显示登录用户发布新主题或新回复的表单,我将forum.php中的表单设置为action="topic_process.php"。然而,我正在与topic_process.php页面作斗争,这里是我的代码,当我试图发布一个主题时,它只是回声出"你不能发布一个新的主题"。

下面是forumtopic表的概述:

forumtopic_id, 
forumtopic_forumcategory_id,
forumtopic_title, 
forumtopic_text,
forumtopic_user_id, 
forumtopic_date, 

下面是我在topic_process.php页面中的代码。(请记住,我没有在任何验证的东西,等,但会做后,我可以得到它张贴到数据库)提前感谢。

<?php
session_start();
include "includes/pagetop.php";

 $query  = "newtopic;";
$result = mysql_query($query);
if(!$result)
{
    echo 'You are not able to post a new topic, please try again later';
}
else
{

    $sql = "INSERT INTO forumreply
    (
                       formtopic_forumcategory_id,
                       forumtopic_title,
                       forumtopic_text,
                       forumtopic_user_id,
                       forumtopic_date
                       )
           VALUES('" . mysql_real_escape_string($_POST['topic_cat']) . "',
                       NOW(),
                       " . mysql_real_escape_string($_POST['topic_cat']) . ",
                       " . $_SESSION['user_id'] . "
                       )";
    $result = mysql_query($sql);

    {
        //the first query worked, now start the second, posts query
        //retrieve the id of the freshly created topic for usage in the posts query
        $topicid = mysql_insert_id();
        $sql = "INSERT INTO forumtopic
                    (
                       formtopic_forumcategory_id,
                       forumtopic_title,
                       forumtopic_text,
                       forumtopic_user_id,
                       forumtopic_date
                          )
                VALUES
                    ('" . mysql_real_escape_string($_POST['post_content']) . "',
                          NOW(),
                          " . $topicid . ",
                          " . $_SESSION['user_id'] . "
                    )";
        $result = mysql_query($sql);
        if(!$result)
        {
            //something went wrong, display the error
            echo 'An error occured while inserting your post. Please try again later.' . mysql_error();
            $sql = "ROLLBACK;";
            $result = mysql_query($sql);
        }
        else
        {
            $sql = "COMMIT;";
            $result = mysql_query($sql);
            //after a lot of work, the query succeeded!
            echo 'You have successfully created <a href="topic.php?id='. $topicid . '">your new topic</a>.';
        }
    }
}


 ?>

     ?>

调试$result变量

你的问题在这里

    $result = mysql_query($query);
    if(!$result)

尝试添加

   $result = mysql_query($query);
   var_dump($result);
   exit();
   if(!$result)

并检查查询

的结果

因为你的问题是什么查询返回