1

What am I doing wrong in my query? thank you in advance for your help

new - not work

$query  = "SELECT * "; 
$query .= "FROM photographs "; 
$query .= "WHERE `caption` LIKE '%".$query."%' ";
    $query .= "OR `caption2` LIKE '%".$query."%' ";
//$query .= "WHERE visible = 1 ";
$query .= "ORDER BY $order_by LIMIT $start, $display ";     
$result = mysqli_query ($connection, $query);

old query - work

//$query = ("SELECT * FROM photographs WHERE (`caption` LIKE '%".$query."%') OR (`caption2` LIKE '%".$query."%')");
//$result = mysqli_query($connection, $query);
MPelletier
  • 16,256
  • 15
  • 86
  • 137
Mantykora 7
  • 173
  • 2
  • 8
  • 19
  • Maybe it wasn't such a good idea to reuse the variable. I also see that you don't use query parameters. I just hope you have sanitized your input. http://xkcd.com/327/ – Klas Lindbäck Oct 21 '13 at 11:35
  • echo the $query value before passing it to mysqli_query function , and take the output and try it on any mysql client that you use such as phpMyAdmin ,and monitor the results – Leo Bali Oct 21 '13 at 11:42

2 Answers2

3

You are overwriting the $query variable with parts of your query. :-)

mkf
  • 700
  • 3
  • 12
1
LIKE '%".$query."%' ";

should be replaced with

LIKE '%".$yourTerm."%' ";

where $yourTerm is what you are trying to search in your database

tCode
  • 444
  • 3
  • 8