-1

我遇到了问题

<?php
//create_cat.php
include 'connect.php';
include 'header.php';

$sql = "SELECT
            topic_id,
            topic_subject,
            topic_cat
        FROM
            topics
        WHERE
            topics.topic_id = " . mysql_real_escape_string($_GET['id']);

$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

echo '<a href="index.php">Nexus</a> > <a href="category.php?id=' . $row['topic_cat'] . '">Category will go here.</a> > <a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a><br>';

if(!$result)
{
    echo 'The topic could not be displayed, please try again later.';
}
else
{
    if(mysql_num_rows($result) == 0)
    {
        echo 'This topic doesn&prime;t exist.';
    }
    else
    {

        {
            //display post data
            echo '<table class="topic">
                    <tr>
                        <th colspan="2">' . $row['topic_subject'] . '</th>
                    </tr>';

            //fetch the posts from the database
            $posts_sql = "SELECT
                        posts.post_topic,
                        posts.post_content,
                        posts.post_date,
                        posts.post_by,
                        posts.post_id,
                        users.user_id,
                        users.user_name,
                        users.user_title,
                    FROM
                        posts
                    LEFT JOIN
                        users
                    ON
                        posts.post_by = users.user_id
                    WHERE
                        posts.post_topic = " . mysql_real_escape_string($_GET['id']);

            $posts_result = mysql_query($posts_sql);

            if(!$posts_result)
            {
                echo '<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
            }
            else
            {
                while($posts_row = mysql_fetch_assoc($posts_result))
                {
                    echo '<tr class="topic-post">

                            <td class="user-post"><div id="user">
                                <b>' . $posts_row['user_name'] . '</b><br/>' . $posts_row['user_title'] . '</div><br/>' . date('m-d-Y h:ia', strtotime($posts_row['post_date'])) . '</td>
                            <td class="post-content">
                            <a name="postid=' . $posts_row['post_id'] . '"></a>
                            ' . htmlentities(stripslashes($posts_row['post_content'])) . '</td>
                          </tr>';
                }
            }

            if(!$_SESSION['signed_in'])
            {
                echo '<tr><td colspan=2>You must be <a href="signin.php">signed in</a> to reply. You can also <a href="signup.php">sign up</a> for an account.';
            }
            else
            {
                //show reply box
                echo '<tr><td colspan="2"><h2>Reply:</h2><br />
                    <form method="post" action="reply.php?id=' . $row['topic_id'] . '">
                        <textarea name="reply-content"></textarea><br /><br />
                        <input id="button" type="submit" value="Submit reply" />
                    </form></td></tr>';
            }

            //finish the table
            echo '</table>';
        }
    }
}

include 'footer.php';
?>

它说

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 10 行的“FROM posts LEFT JOIN users ON posts.post_by = u”附近使用正确的语法

在底部(我添加了一个 echo mysql_error(); 在底部)。这是相当重要的,因为它是其他人实际使用的论坛软件,它在我的网站上支持大约 4 种不同的东西(似乎过多,但所有暂时都连接到同一个数据库,一个用于积极开发它,并且其他用于实际软件)。

4

2 回答 2

3

from您在要删除的子句前有多余的逗号,

SELECT
        posts.post_topic,
        posts.post_content,
        posts.post_date,
        posts.post_by,
        posts.post_id,
        users.user_id,
        users.user_name,
        users.user_title   // << remove extra comma here
FROM
        posts
LEFT JOIN
        users
ON
        posts.post_by = users.user_id
于 2013-01-06T04:15:07.460 回答
0

SELECT第 49 行 - 在列表中的最后一项之后有一个逗号。

于 2013-01-06T04:15:12.000 回答