I stored some multiple id values from a form[] in a session.
I tried to use these id's within a mysql pdo database query as follow:
$noot = str_repeat("?,", count($_SESSION['uniqueID'])-1) . "?";
$printen = 1;
$query = $db->prepare("SELECT DISTINCT ru.GB,g.Name,g.Address,g.Place,ri.Ricode,lo.nr,lo.uniqueID,GROUP_CONCAT(ru.control SEPARATOR '<BR>') AS control,GROUP_CONCAT(ru.BestEmail SEPARATOR '<BR>') AS email,GROUP_CONCAT(ru.ont_info SEPARATOR '<BR>') AS ont,GROUP_CONCAT(ru.sup SEPARATOR '<BR>') AS Lev,GROUP_CONCAT(ru.OrderID SEPARATOR '<BR>') AS orderID,GROUP_CONCAT(DISTINCT ru.rID SEPARATOR '<BR>') AS RID,GROUP_CONCAT(ru.Pack SEPARATOR '<BR>') AS packet FROM rutrans AS ru JOIN routes AS ri ON ru.rID = ri.rID
LEFT OUTER JOIN lock AS lo
ON ri.Ricode = lo.ricode AND ru.GB = lo.location
LEFT OUTER JOIN gbc AS g
ON ru.GB = g.CodeB
WHERE lo.uniqueID IN ($noot)");
$query->execute($_SESSION['uniqueID']);
//$data = $query->fetchAll();
And try to get the results like this:
foreach($queryRT as $rowRT) {
(I echo database results within a table for each row here,... or try to do this)
}
The following error occures:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number' in
When I add
$data = $query->fetchAll();
to the query the page is totally blank.
When I try something to show like this:
print_r($data);
Only the following is being displayed on the page:
Array ( )
When I try something like this:
print_r($_SESSION['uniqueID']);
It shows the array as follow:
Array ( [B1601222016164345] => B1601222016164345
[B1601222016161121] => B1601222016161121
[B1601262126474345] => B1601262126474345
[B1602011856554345] => B1602011856554345
[B1602101921434345] => B1602101921434345
[Z1602102002034345] => Z1602102002034345
[Z1602102026544345] => Z1602102026544345
)
Obviously I am doing something totally wrong. Is there anybody who would have an idea to solve this problem?
$nootis actually being produced properly. you maybe be generating (say)?,?,?, but then providing only 2 values for those placeholders.