继续得到语法错误,但我无法检测到任何错误

时间:2015-04-09 04:09:03

标签: php mysql

也许这里的任何人都可以帮我查找这段代码中的任何错误。因为我已经找了几天但却找不到任何东西。请帮我。谢谢。

$id = $_GET['id'];
$tid = $_GET['tid'];

$sql = "SELECT * FROM ftopics WHERE categoryId ='".$id."' AND id='".$tid."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());

                   if (mysql_num_rows($res) == 1){
                   echo "<table width = '100%'>";
                   if ($_SESSION['user']){
                   echo "<tr><td colspan = '2'><input type = 'submit' value = 'Add Reply' onClick=\"window.location=
                   'postReply.php?id=".$id."&tid=".$tid."'\" />";
                   echo "  | <a href='main.php'>Back to main page</a><hr />";
                   }
                   else {
                    echo "<tr><td colspan='2'>
                    <p>Please log in to add your reply.</p></td></tr>";
                    }
                    while ($row=mysql_fetch_assoc($res)){
                          $title = $row['topicTitle'];
                          $sql2 = "SELECT * FROM fposts WHERE categoryId='".$id."' AND topicId='".$tid."'";
    `                     $res2 = mysql_query($sql2) or die(mysql_error());
                          while ($row2=mysql_fetch_assoc($res2)){
                            $creator = $row2['postCreator'];
                            $date = $row2['postDate'];
                            $content = $row2['postContent'];
                                       echo "<tr><td valign='top' style='border:1px solid #000000;'>";
                                       echo "<div style='min-height:125px;'>".$title;
                                       echo "<br>by ".$creator." - ".$date."<hr />".$content."</div></td><td width='200' valign ='top'";
                                       echo "align='center' style ='border:1px solid #000000;'>User Info Here</td></tr><tr><td colspan ='2'><hr /></td></tr>";
                                       }

3 个答案:

答案 0 :(得分:1)

删除以下行之间不需要的字符(`),如下所示:

$sql2 = "SELECT * FROM fposts WHERE categoryId='".$id."' AND topicId='".$tid."'";
$res2 = mysql_query($sql2) or die(mysql_error());

答案 1 :(得分:0)

是的,您可以从sql中删除那些额外的引号

$sql = "SELECT * FROM ftopics WHERE categoryId = ".$id." AND id=".$tid." LIMIT 1";

$sql2 = "SELECT * FROM fposts WHERE categoryId=".$id." AND topicId=".$tid.";

尝试一下。

答案 2 :(得分:0)

不知道,但您可能不小心将`列入了代码中的额外反引号

$sql2 = "SELECT * FROM fposts WHERE categoryId='".$id."' AND topicId='".$tid."'";
    `                     $res2 = mysql_query($sql2) or die(mysql_error());
   ^^^//over here 

删除它,它将作为魅力