开发者

searching for multiple columns mysql and php

开发者 https://www.devze.com 2022-12-31 17:20 出处:网络
i\'m trying to search for multiple columns using this code: <?php // Connection Database $search = $_POST [\'Search\'];

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>开发者_Go百科".$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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消