Search code examples
phpmysqlpdosql-like

Issue with Like Query in MYSQL PHP


Following problem:

If I want to search with 'Last Name' it works but if it is a variable in this form $results['22']['BuyerName2']

Here is what I got so far:

$rr=$results[22]['BuyerName2'];
echo $rr; //echos Last Name

$stmt = $db->prepare("Update base_1 SET UpdateStatus=2 WHERE BuyerName LIKE ?");
$stmt->bindValue(1, "%$rr%", PDO::PARAM_STR);
$stmt->execute();

If I put instead $rr the Name directly in the bind value part it works. But not with $rr.


Solution

  • Maybe there are extra spaces in $rr. Try:

    $rr = trim($results[22]['BuyerName2']);