【问题标题】:Page number code error页码代码错误
【发布时间】:2013-12-02 19:05:11
【问题描述】:

我在运行此代码时收到此错误:

Parse error: syntax error, unexpected '$page_number' (T_VARIABLE) in C:\wamp\www\SearchEngine\search.php on line 5

search.php 的代码:

<?php
//php code goes here
include 'connect.php'; // for database connection
$query = $_GET['q'] // query
$page_number = $_GET['page'];
?>
<html>
    <head>
        <title>
            Brandon's Search Engine
        </title>
        <style type="text/css">
            #search-result {
                font-size: 17pt;
                margin: 5px;
                padding: 2px;
                border-color: black;
            }
            #search-result:hover {
                border-color: 1px solid red;
                background-color: #cccccc;
            }
            #name {
                color: #ff9999;
            }
            #name:hover {
                text-decoration: underline;
            }
        </style>
    </head>
    <body>
        <form method="GET" action="search.php">
            <table>
                <tr>
                    <td>
                        <h2>
                            Brandon's Search Engine
                        </h2>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="text" value="<?php echo htmlspecialchars($_GET['q']); ?>" name="q" size="80" name="q"/>
                        <input type="submit" value="Search" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <?php
                        //SQL query
                        $stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' LIMIT $page_number, 10";
                        $result = mysqli_query($con,$stmt) or die(mysqli_error($con));
                        $number_of_result = mysqli_num_rows($result);
                        if ($number_of_result < 1) {
                            echo "Your search did not match any documents. Please try different keywords.";
                        } else {
                            //results found here and display them
                            $index = 0;
                            while (($row = \mysqli_fetch_assoc($result)) && ($index < 10)) {//10 results per page
                                $title = $row["title"];
                                $link = $row["link"];
                                echo "<div id='search-result'>";
                                echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
                                echo "<br />";
                                echo "<div id='link'><small>" . $link . "</small></div>";
                                echo "</div>";
                                $index++;
                            }
                        }
                        ?>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="hidden" name="page" value="<?php echo $page_number+10";
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

我相信这段代码还是有很多错误的。

有人可以帮我解释一下吗,以便我也能理解和学习一些东西?

【问题讨论】:

  • 可能是因为第一次进入页面时$_GET['page']没有填写。
  • 第 4 行缺少分号,因此第 5 行出现错误。$query = $_GET['q'] // query

标签: php search-engine


【解决方案1】:

你错过了一个“;”这里$query = $_GET['q'] // query

还可以查看 Parixit 在他的回答中提到的内容。也是错的。

【讨论】:

  • + 他从不关闭最后一个 PHP 标签。
  • 确实如此。它会打下一个:)
【解决方案2】:

请在$_GET['q']之后添加;

并关闭最后一个php标签

<td>
    <input type="hidden" name="page" value="<?php echo $page_number+10; ?>" />
</td>

【讨论】:

  • Srsly,请接受我的编辑,你的代码有语法错误。
  • @Daniel 我在为 $_GET 编辑后稍后查看了它,对不起!
【解决方案3】:

在第 4 行 $query = $_GET['q'] 你忘了用 ; 结束你的代码

您还需要像这样在第 75 行关闭 php 标签 &lt;?php echo $page_number+10 应该是 &lt;?php echo $page_number+10; ?&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    相关资源
    最近更新 更多