页码代码错误

时间:2013-12-02 10:34:42

标签: php search-engine

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

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>

我相信此代码中仍有很多错误。

有人可以帮助我并向我解释,以便我能理解并学到一些东西吗?

3 个答案:

答案 0 :(得分:2)

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

也看看Parixit在他的回答中提到了什么。这也是错误的。

答案 1 :(得分:1)

请在;

之后添加$_GET['q']

关闭最后一个php代码

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

答案 2 :(得分:0)

在第4行$query = $_GET['q'],您忘记使用;

结束代码

你还需要在第75行关闭你的php标签 <?php echo $page_number+10应为<?php echo $page_number+10; ?>