0

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.

2
  • Are you sure you're using double quotes, not single quotes? Commented Aug 16, 2014 at 0:08
  • And when you say it doesn't work, what happens exactly? Do you get an error? If so, what's the error? Or does it just not update anything? Commented Aug 16, 2014 at 0:11

2 Answers 2

3

Maybe there are extra spaces in $rr. Try:

$rr = trim($results[22]['BuyerName2']);
Sign up to request clarification or add additional context in comments.

Comments

1

In the line:

$stmt->bindValue(1, "%$rr%", PDO::PARAM_STR);

I am unsure whether the $ becomes escaped or not in the string you binded. As far as I know, only the underscore and the percent sign stay unescaped. I would suggest to try:

$rr = "%".$rr."%";

and edit the line to:

$stmt->bindValue(1, $rr, PDO::PARAM_STR);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.