-2
$raw_results = mysql_query("SELECT * FROM system_passwords 
    WHERE hide != 1 AND (`id` LIKE '%".$query."%') 
    OR (`system_name` LIKE '%".$query."%') 
    OR (`database_name` LIKE '%".$query."%') 
    OR (`username` LIKE '%".$query."%') 
    OR (`password` LIKE '%".$query."%') 
    OR (`notes` LIKE '%".$query."%') 
    OR (`additional_info` LIKE '%".$query."%')") or die(mysql_error());

How or where do I add hide != 1 into this?

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
deansmith
  • 1
  • 2

2 Answers2

2

You have to group the ors together. As is your query runs as

WHERE hide != 1 AND (`id` LIKE '%".$query."%')

or

(system_name LIKE '%".$query."%')

or etc.

This should group the values as you expect.

SELECT * FROM system_passwords 
WHERE (
        (`id` LIKE '%".$query."%') OR 
        (`system_name` LIKE '%".$query."%') OR 
        (`database_name` LIKE '%".$query."%') OR 
        (`username` LIKE '%".$query."%') OR 
        (`password` LIKE '%".$query."%') OR 
        (`notes` LIKE '%".$query."%') OR 
        (`additional_info` LIKE '%".$query."%')
    ) and hide != 1

You also should switch over to PDO or mysqli so you can use prepared statements. This may open you to SQL injections; not knowing what $query can't say for certain..

Additional information: Mysql or/and precedence?

Community
  • 1
  • 1
chris85
  • 23,846
  • 7
  • 34
  • 51
1

It is in the right place, but this is less ambiguous logically WHERE hide != 1 AND ([a] OR [b] OR [c])

Uueerdo
  • 15,723
  • 1
  • 16
  • 21