正如标题所示,我收到“无法显示主题,请稍后再试。”错误信息,但数据插入到我的mysql表中很好,但我无法弄清楚它们为什么不显示,这里是我的结果页面。
<?php
include 'core/init.php';
include 'includes/overall/header.php';
$sql = "SELECT 'topic_id', 'topic_subject', 'category', 'sub_category', 'posted_by', 'posted', 'view', 'reply' FROM `topics`
WHERE topics.topic_id = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
if(!$result)
{
echo 'The topic could not be displayed, please try again later.';
}
else
{
if(mysql_num_rows($result) == 0)
{
echo 'This topic doesn′t exist.';
}
else
{
while($row = mysql_fetch_assoc($result))
{
$posts_sql = "SELECT 'posts.post_topic', 'posts.post_content', 'posts.post_date', 'posts.post_by',
'users.user_id', 'users.username', 'users.profile'
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))
{
include("includes/results-template.php");
}
}
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 type="submit" value="Submit reply" />
</form></td></tr>';
}
//finish the table
echo '</table>';
}
}
}
?>
<?php include 'includes/overall/footer.php'; ?>
答案 0 :(得分:0)
您不能选择带单引号的列,而应选择带反引号的列。
将您的查询更改为
$sql = "SELECT `topic_id`, `topic_subject`, `category`, `sub_category`, `posted_by`, `posted`, `view`, `reply` FROM `topics`
WHERE topics.topic_id = '".mysql_real_escape_string($_GET['id'])."' ";
并将此查询$posts_sql
更改为:
$posts_sql = "SELECT posts.post_topic, posts.post_content, posts.post_date, posts.post_by, users.user_id, users.username, users.profile
FROM
`posts`
LEFT JOIN
`users`
ON
posts.post_by = users.user_id
WHERE
posts.post_topic = '" . mysql_real_escape_string($_GET['id'])."' ";
反引号和单引号之间有不同。