0

有人可以帮助我创建我的论坛时遇到问题。

在用户可以创建帖子的那一刻,帖子标题列在页面下方,然后假设用户能够单击标题链接并被带到 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>
4

1 回答 1

0

You have an error in your query... Your parameter is not quoted...

 $query = "SELECT *
     FROM ptb_forum, ptb_profiles
     WHERE ptb_forum.id = '$forum_id'";

However... I suggest that you refrain from using the mysql_ family of functions. They are deprecated and due to be removed from PHP in a future release. You should be using parameterized queries using MySQLi or PDO.

Also, global is evil. I've never had a need to use it in 10 years of PHP programming. Neither should you.

于 2013-02-05T15:35:48.997 回答