有人可以帮助我,我在创建论坛时遇到了问题。
目前用户可以创建帖子,帖子标题列在页面下方,然后用户可以点击标题链接并转到read_post.php然后这会将用户带到另一个页面在哪里可以查看帖子内容,我试图通过回应论坛帖子ID来做到这一点,但它似乎不想工作,而是我得到这个错误:
Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
有人可以告诉我哪里出错了。
这是我的sql函数:
function read_forum() {
global $connection;
global $forum_id;
$query = "SELECT *
FROM ptb_forum, ptb_profiles
WHERE ptb_forum.id = $forum_id ";
$forum_set = mysql_query($query, $connection);
confirm_query($forum_set);
return $forum_set;
}
这是将用户带到read_post.php的链接代码,它假设回显论坛ID并显示每个帖子的内容。
<?
$forum_set = get_forum();
while ($forum = mysql_fetch_array($forum_set)) {
?>
<div class="forumcase" id="forumcase">
<div class="pend-forum-content">
<?php echo "<strong><a href=\"read_post.php?post={$forum_id['id']}\">{$forum['title']}</a></strong> - Posted by {$user['first_name']}"; ?>
</div>
here's my code for read_post.php:
<?php
$page_title = "Read Post";
include('includes/header.php');
include ('includes/mod_login/login_form2.php'); ?>
<?php
confirm_logged_in();
if (isset ($_GET['frm'])) {
$forum_id = $_GET['frm'];
}
?>
<?php include('includes/copyrightbar.php'); ?>
<div class="modtitle">
<div class="modtitle-text">Messages Between <?php echo "{$forum['display_name']}"; ?> & You</div>
</div>
<div class="modcontent57">
<br /><br /><br/><br/>
<div class="forum">
<div class="forum-pic"><?php echo "<img src=\"data/photos/{$_SESSION['user_id']}/_default.jpg\" width=\"100\" height=\"100\" border=\"0\" align=\"right\" class=\"img-with-border-forum\" />";?>
</div>
<div class="message-links">
<strong><a href="forum.php"><< Back to Forum</a>
</div>
<br /><br /><br/><br/>
<?php
$datesent1 = $inbox['date_sent']; ?>
<?php
$forum_set = read_forum();
while ($forum = mysql_fetch_array($forum_set)) {
$prof_photo = "data/photos/{$message['user_id']}/_default.jpg";
$result = mysql_query("UPDATE ptb_forum SET ptb_forum.read_forum='1' WHERE ptb_forum.id='$forum_id'")
or die(mysql_error());
?>
<div class="message-date">
<?php echo "".date('D M jS, Y - g:ia', strtotime($message['date_sent'])).""; ?></div>
<div class="img-with-border-msg-read"><?php echo "<a href=\"profile.php?id={$forum['from_user_id']}\"><img width=\"60px\" height=\"60px\" src=\"{$prof_photo}\"></a><br />"; ?></div>
<div class="conversation-text">
<?php echo "<i>Conversations between you and<a href=\"profile.php?id={$forum['from_user_id']}\"> </i>{$forum['display_name']}.</a><br /> "; ?></div>
<div class="message-content">
<?php echo "<strong>Message Subject: </strong><i>{$forum['subject']}</i>"; ?>
<br/>
<br/>
<br/>
<br/>
<?php echo "<strong>Message:<br/></strong></br ><i>{$forum['content']}</i>"; ?>
</div>
<div class="reply-box">
<? include ('message_reply.php'); ?>
</div>
<?php
}
?>
<br/>
<br/>
<br/>
</div>
</div>
<?php include('includes/footer.php'); ?>
</div>
答案 0 :(得分:0)
您的查询中有错误...您的参数未引用...
$query = "SELECT *
FROM ptb_forum, ptb_profiles
WHERE ptb_forum.id = '$forum_id'";
然而......我建议您不要使用mysql_
系列函数。它们已被弃用,并将在未来版本中从PHP中删除。您应该使用MySQLi或PDO使用参数化查询。
此外,global
是邪恶的。我从来没有需要在10年的PHP编程中使用它。你也不应该。