0

I have a SQL query that looks for a user by using a address and by using a city.

The address part uses a WHERE operator but the city uses a LIKE operator. If I remove the Like operator and just leave the WHERE operator for the address, it works. But once I add the LIKE operator to compare the city, I get nothing, no errors or anything just nothing is returned.

Here is my code, thank you in advance:

$stmtCont = $connection->prepare(
   "SELECT * FROM `mycontacts` WHERE `CustomerAddress` = ? AND `CustomerState` LIKE ?");
$stmtCont->execute(array($scannedAddress, '$scannedCity%'"));
$customerResult = $stmtCont->fetchAll();
print_r($customerResult);
Zanshin13
  • 980
  • 4
  • 19
  • 39
user2684521
  • 380
  • 4
  • 20
  • 1
    That looks like you checking for customer state, not city. – Uueerdo Sep 09 '15 at 21:46
  • Wow I cant believe I overlooked that. Thank you very much. – user2684521 Sep 09 '15 at 21:47
  • Also: `'$scannedCity%'` will be... literally that. I think you want `$scannedCity.'%'`. – samlev Sep 09 '15 at 21:49
  • 2
    `WHERE` is not a an operator. Everything after `WHERE` is the conditions, and the operators are `=` and `LIKE`. – Barmar Sep 09 '15 at 21:51
  • poor question title; `like` operator is working, your assumption is incorrect – vol7ron Sep 09 '15 at 23:49
  • with `'$scannedCity%'"`, what's that trailing `"` supposed to do? why do you expect to interpolate inside literal strings? are you sure you want to compare states that are named similar to cities? – vol7ron Sep 09 '15 at 23:51

0 Answers0