Try the following:
<?php mysql_connect("localhost","username","password"); mysql_select_db("database"); if(!empty($_GET['q'])){ $query=mysql_real_escape_string(trim($_GET['q'])); $searchSQL="SELECT * FROM links WHERE `title` LIKE '%{$query}%' LIMIT 8"; $searchResult=mysql_query($searchSQL); if(mysql_num_rows($searchResult) <= 0) { echo "No results"; } else { while ($row=mysql_fetch_assoc($searchResult)){ $results[]="<div class='webresult'><div class='title'><a href='{$row['url']}'>{$row['title']}</a></div><div class='desc'>{$row['description']}</div><div class='url'>{$row['url']}</div></div>"; } echo implode($results); } } ?>
Also, please use MySQLi or PDO, as it is safer and better to use, some information can be found below. Personally, I prefer MySQLi, but the prepared statements in PDO are really good and save some lines of code every time you query;)
MySQLi and PHP
PDO and PHP
source share