Jump to content

What's wrong with my php code?


jasoncdenson

Recommended Posts

I have received an error when I run this code:

Parse error: syntax error, unexpected 'while' (T_WHILE) in C:\wamp\www\SearchEngine\search.php on line 50

Code:

<?php
//php code goes here
include 'connect.php'; // for database connection
$query = $_GET['q'] // query
?>
<html>
    <head>
        <title>
            Brandon's Search Engine
        </title>
        <style type="text/css">
            #search-result {
                font-size: 22;
                margin: 5px;
                padding: 2px;
            }
            #search-result:hover {
                border-color: red;
            }
        </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 $_GET['q']; ?>" name="q" size="80" name="q"/>
                        <input type="submit" value="Search" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <?php
                        //SQL query
                        $stmt = "SELECT * FROM web WHERE title LIKE '%$query%' OR link LIKE '%$query%'";
                        $result = mysql_query($stmt);
                        $number_of_result = mysql_num_rows($result);
                        if($number_of_result < 1)
                            echo "No result found. Please try with other keyword.";
                        else
                        (
                                //results found here and display them
                                while($row = mysql_fetch_assoc($result))
                                (
                                    $title = $row["title"];
                                    $link = $row["link"];
                                    echo "<div id='search-result'>";
                                    echo "<div id='title'" . $title . "</div>";
                                    echo "<br />";
                                    echo "<div id='link'" . $link . "</div>";
                                    echo "</div>";
                                )
                        )
                        ?>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

Thanks.

 

Link to comment
Share on other sites

You need to use curly braces for code blocks { and }. Not parenthesesis ( and )

                        if($number_of_result < 1)
                            echo "No result found. Please try with other keyword.";
                        else
                        { // open curly brace
                                //results found here and display them
                                while($row = mysql_fetch_assoc($result))
                                {  // open curly brace
                                    $title = $row["title"];
                                    $link = $row["link"];
                                    echo "<div id='search-result'>";
                                    echo "<div id='title'" . $title . "</div>";
                                    echo "<br />";
                                    echo "<div id='link'" . $link . "</div>";
                                    echo "</div>";
                                }  // close curly brace
                        }  // close curly brace
                        ?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.