Problem with MySQL Search
Posted: Sat Aug 30, 2008 2:11 pm
Hi,
I have created what I think is quite a simple search function but at the moment it keeps throwing back 'No results found' at me and I can't work out why. The script is quite small so I've included it here. Can anyone see what the problem might be? I've double-checked everything many times in case there's a mistake but can't see anything.
This is the form:
And this is the search.php file:
I have created what I think is quite a simple search function but at the moment it keeps throwing back 'No results found' at me and I can't work out why. The script is quite small so I've included it here. Can anyone see what the problem might be? I've double-checked everything many times in case there's a mistake but can't see anything.
This is the form:
Code: Select all
<form method="POST" action="search.php"> Search the code repository:<br /> <input type="text" id="keyword" name="keyword" /><br /> <input type="submit" value="Search!" /> </form>And this is the search.php file:
Code: Select all
<?php
mysql_connect("128.0.0.1","asad","secret");
mysql_select_db("asad");
$keyword = mysql_real_escape_string($_POST['keyword']);
// Perform the fulltext search
$query = "SELECT ID, FirstName, LastName, Organisation, OrgType
FROM Contacts WHERE MATCH(OrgType) AGAINST ('$keyword')";
$result = mysql_query($query);
// If results were found, output them
if (mysql_num_rows($result) > 0) {
printf("Results: <br />");
while ($row = mysql_fetch_array($result)) {
printf($row['FirstName'], $row['LastName'], $row['Organisation']);
}
} else {
printf("No results found");
}
?>