drl92080 2017-06-07 15:44
浏览 95

论坛SQL语法错误

Hello I am trying to build a forum, but when I click over the topic of my forum I can view the page. I get the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''7'' at line 1

Here is my code from the view_topic.php page that I am trying to build:

    <?php
    session_start(); 

    ?>
    <!DOCTYPE html>
    <html>
    <head>
         <title>View Category</title>
         <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <body>
    <div id="wrapper">
           <h2>Timkipptutorials</h2>


        <?php
         if(!isset($_SESSION ['uid'])){
             echo "<form action='login_parse.php' method='post'>
              Username: <input type='text' name='username'>&nbsp;
              Password <input type='text' name='password'>&nbsp;
              <input type='submit' name='submit' value='Log In'>" ;
        }
         else{
           echo "<p>You are logged in as ".$_SESSION['username']." &bull; <a            href='logout_parse.php'> Logout</a>";
        }
           ?>

    <hr>
    <div id="content">
            <?php
                include_once("connect.php");

                $cid = $_GET['cid'];
                $tid = $_GET['tid'];
                $sql = "SELECT * FROM topics WHERE category_id='".$cid."' AND           id='".$tid."' LIMIT 1";
                    $res = mysql_query($sql) or die(mysql_error());
                if(mysql_num_rows($res) == 1){
                    echo "<table width='100%'>";
                    if(isset($_SESSION['uid'])){
                            echo "<tr><td colspan='2'><input type='submit'          value='Add Reply' onClick=\"window.location = 'post_reply.php?          cid=".$cid."$tid=".$tid."'\"/><hr>";
                    }else{
                        echo "<tr><td colspan='2'><p>Please log in to add a reply</p><hr></td></tr>";
                    }
                    while ($row = mysql_fetch_assoc($res)) {
                        $sql2 = "SELECT * FROM posts WHERE category_id = '".$cid."' AND topic_id '".$tid."'";
                        $res2 = mysql_query($sql2) or die(mysql_error());
                        while($row2 = mysql_fetch_assoc($res2)){
                            echo "<tr><td valign='top' style='border: 1px           solid #000000;'><div style='min-height: 125px;'>".$row['topic_title']."<br> by          ".$row2['post_creator']. " - ".$row2['post_date']."<hr>".$row2['post_content']."        </div></td><td width='200' valign='top' align='center' style='border: 1px solid         #000000;'>User Info Here</td></tr><tr><td colspan='2'><hr></td></tr>";
                        }
                        $old_views = $row['topic_views'];
                        $new_views = $old_views + 1;
                        $sql3 = "UPDATE topics SET topic_views='".$new_views."' WHERE category_id='".$cid."' AND id='".$tid."' LIMIT 1";
                        $res3 = mysql_query($sql3) or die(mysql_error());
                    }

                    echo "</table>";

                }else{
                    echo "<p>This topic does not exist.</p>";
                }
            ?> 

        </div>
    </div>
    </body>
    </html>

Please help me with that. Thanks

  • 写回答

2条回答 默认 最新

  • dro80463 2017-06-07 15:59
    关注

    $sql2 = "SELECT * FROM posts WHERE category_id = '".$cid."' AND topic_id '".$tid."'";

    is missing the = sign on the second compare... as in

    $sql2 = "SELECT * FROM posts WHERE category_id = '".$cid."' AND topic_id = '".$tid."'";

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿