-1

Hi guys I have this query:

$URLA=implode("','",$Array);
$Data=$connection->prepare("SELECT Category,ID FROM SITES WHERE URL IN('".$Array."') AND Email=:Email ORDER BY Category DESC");
$Data->bindValue(':URL', $URL);
$Data->bindValue(':Email', $Email);
$Data->execute();

This code give this error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens. How can I solve this problem? Note that Array is a variable that comes out from a while loop.And contain more that one variable. I tryied bind this array like this:

$Data->bindValue(':Array', $Array);

But this didn't worked :'(

user9154057
  • 1
  • 1
  • 1
  • 2

1 Answers1

0

As you mentioned, your array looks like this array(1,2,'ABC');,

try this

$URLA= implode("', '", $array); # wrapping with single quote 

$Data=$connection->prepare("SELECT Category,ID FROM SITES WHERE URL IN(".$URLA.") AND Email=:Email ORDER BY Category DESC");
// $Data->bindValue(':URL', $URL); Seems no longer needed.
$Data->bindValue(':Email', $Email);

Or

$URLA= implode("', '", $array); # wrapping with single quote 

$Data=$connection->prepare("SELECT Category,ID FROM SITES WHERE URL IN(:url) AND Email=:Email ORDER BY Category DESC");
$Data->bindValue(':URL', $URLA);
$Data->bindValue(':Email', $Email);
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85