1

i'm trying to search for multiple columns using this code:

 <?php

 // Connection Database
 $search = $_POST ['Search'];

mysql_connect("xxxxxx", "xxxxxx", "xxxxx") or die ("Error Connecting to Database");
mysql_select_db("xxxxx") or die('Error');
    $data = mysql_query("SELECT CourseName, CourseDescription, CourseLeader FROM course   MATCH (CourseName, CourseDescription, CourseLeader) AGAINST ('". $search ."')
or die('Error');
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
 {
  Print "<tr>";
  Print "<th>Course Name:</th> <td>".$info['CourseName'] . "</td> ";
  Print "<th>Course Description:</th><td>".$info['CourseDescription'] . "</td> ";
  Print "<th>Course Leader:</th><td>".$info['CourseLeader'] . " </td></tr>";

  }
  Print "</table>";

   ?>

i'm getting the following error: Parse error: syntax error, unexpected T_STRING in /home/a7105766/public_html/website/scripts/coursesearchdb.php on line 30

what am I doing wrong??

cheers

1 Answer 1

3

This line is incorrect:

$data = mysql_query("SELECT ... AGAINST ('". $search ."') or die('Error');

You can even see the error from the syntax highlighting that Stack Overflow uses. Do you use syntax highlighting when developing? If not, I'd recommend it for catching exactly this sort of error.

The solution - you need to close the double-quote and the open parenthesis.

$data = mysql_query("SELECT ... AGAINST ('". $search ."')") or die('Error');

Also instead of die('Error') you could write something useful such as die(mysql_error()). You could also look at trigger_error(mysql_error()).

In your SQL you are missing the keyword WHERE. See Full-Text Search Functions in the manual for more information on full text searches.

Sign up to request clarification or add additional context in comments.

11 Comments

@addi: See my update: Don't use die('Error') - that's incredibly unhelpful for debugging. Change it to die(mysql_error()). This should give you the error message for your query, which should hopefully allow you to find the error yourself.
im getting this now: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MATCH (CourseName, CourseDescription, CourseLeader) AGAINST ('')' at line 1 no idea what it means!! is MATCH wrong?
i added WHERE to MATCH and now i'm getting this error message: Can't find FULLTEXT index matching the column list
@addi: Well I think that message is quite self-explanatory... you don't have a full text index for one of the columns.
i'm sorry but i'm really new at this, do I have to add this fullindex search to my table? I don't quite understand. cheers
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.