0

I have been struggling with a search function and now when I want to rewrite my table i have to get all my data from my database again.

But now when i use this code I get:

Parse error: syntax error, unexpected T_LOGICAL_OR in ..

My code:

$raw_results = mysql_query("SELECT `statusref`.`status_ID`, `tblapparaten`.*, `status`.`status`  FROM `tblapparaten` 
            LEFT JOIN `opvolging`.`statusref` ON `tblapparaten`.`apparaat_id` = `statusref`.`apparaat_ID`
            LEFT JOIN `opvolging`.`status` ON `statusref`.`status_ID` = `status`.`status_ID`
            WHERE (`apparaat` LIKE '%".$query."%') 
            OR (`serienummer` LIKE '%".$query."%') 
            OR (`klacht` LIKE '%".$query."%') 
            ORDER BY $field $sort ");
Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • Thanks for editing, i'm new to this site and have no idea how to post code decently. – Bert van Dijck May 06 '15 at 08:27
  • Firstly, mysql is deprecated and should no longer be used, switch to mysqli or PDO instead. – Epodax May 06 '15 at 08:27
  • 1
    What are the values of `$query`, `$field` and `$sort` ? – Daan May 06 '15 at 08:28
  • @BertvanDijck Then I think these 2 links will help you much: http://stackoverflow.com/tour , http://stackoverflow.com/help – Rizier123 May 06 '15 at 08:28
  • I have a project going and this is like my first time i do things like this for my last year on school. We have learned it with mysql and i know its outdated but i'm afraid to switch to mysqli for messing up the whole project. – Bert van Dijck May 06 '15 at 08:29
  • $query contains the string which i gave in an input for the search function. $field and $sort are used for sorting my table. – Bert van Dijck May 06 '15 at 08:30
  • @BertvanDijck Show us the values with `var_dump($query);` ... -> output?! [Edit](http://stackoverflow.com/posts/30071296/edit) your question! – Rizier123 May 06 '15 at 08:31
  • Sorry but i have no idea how this all works .. – Bert van Dijck May 06 '15 at 08:33
  • i have a table with information and when i type into the search bar "BOSCH" and press the submit button then $query will be "BOSCH" – Bert van Dijck May 06 '15 at 08:35
  • @BertvanDijck 1. Add the following lines in your code right before you run your sql query: `var_dump($query); var_dump($sort); var_dump($field);` 2. Take the output of all 3 which will be something like: `string(2) "xy"` and edit your question 3. Use the [**edit**](http://stackoverflow.com/posts/30071296/edit) button! (4. Format it nicely! How? -> http://stackoverflow.com/help/formatting) – Rizier123 May 06 '15 at 08:35
  • @BertvanDijck Also add on which line the error occurs and mark it with a comment in the question – Rizier123 May 06 '15 at 08:41
  • `T_LOGICAL_OR` is the literal operator `or`. Are you sure the error is in the code you have given? Which line does it point to exactly? I can only assume a missing quote somewhere is causing the `OR` to be read as PHP and not part of the MySQL string... – Niet the Dark Absol May 06 '15 at 08:41
  • @NiettheDarkAbsol Or it's one line above the code which we see :) – Rizier123 May 06 '15 at 08:42
  • Can you show us the statement after processing? (I.e. without ".$query. etc.) – jarlh May 06 '15 at 08:45
  • Guys i appreciate the help^but i've got my way out on another way :D i just copied to much code to another... the ORDER BY part was to much here i didnt need it – Bert van Dijck May 06 '15 at 08:46

0 Answers0