jasoncdenson Posted November 25, 2013 Share Posted November 25, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284245-whats-wrong-with-my-php-code/ Share on other sites More sharing options...
Ch0cu3r Posted November 25, 2013 Share Posted November 25, 2013 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/284245-whats-wrong-with-my-php-code/#findComment-1459938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.