Page 1 of 1

Problem with MySQL Search

Posted: Sat Aug 30, 2008 2:11 pm
by slaterino
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:

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");
  }
 
?>

Re: Problem with MySQL Search

Posted: Sat Aug 30, 2008 9:04 pm
by marcth
I probably shouldn't be responding to your post as I haven't used mySQL for several years. Is case-sensitivity the problem?

Re: Problem with MySQL Search

Posted: Sat Aug 30, 2008 10:36 pm
by Cut
I think it's matching against "$keyword," literally. You could try echoing $query to check. If it is, use:

Code: Select all

$query = "SELECT ID, FirstName, LastName, Organisation, OrgType FROM Contacts WHERE MATCH(OrgType) AGAINST ('".$keyword."')";