0

$emptyNumbers has 2 items and $qMarks is " ?,? ". What is the problem?

if(($key = array_search($row['nummer'], $emptyNumbers)) !== false) {
unset($emptyNumbers[$key]);
}
echo sizeof($emptyNumbers)."==>".$qMarks;  // 2 ==> ?,?
$qMarks = str_repeat('?,', count($emptyNumbers)-1) . '?';
$getPlayerData=$db->prepare( "SELECT number,surname,firstname,position,job FROM player WHERE nummer IN ($qMarks)");         
$getPlayerData->execute($emptyNumbers);

--> Error: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
8
  • 1
    write only $getPlayerData->execute(); Commented Nov 18, 2015 at 18:50
  • Then I get the error "no parameters were bound". Commented Nov 18, 2015 at 18:52
  • in which line you got error Commented Nov 18, 2015 at 18:55
  • no need to bound any parameter without bounding pdo work as well as Commented Nov 18, 2015 at 18:56
  • It would be helpful if you would var_dump($emptyNumbers); and show us that output. Commented Nov 18, 2015 at 19:13

1 Answer 1

1

The problem was that I previously unset values from $emptyNumbers and I did not reorder the array so that there were empty values.

if(($key = array_search($row['nummer'], $emptyNumbers)) !== false) {
unset($emptyNumbers[$key]);
//delete the gaps in the array!
$emptyNumbers = array_values($emptyNumbers);
}

$qMarks = str_repeat('?,', count($emptyNumbers)-1) . '?';
$getPlayerData=$db->prepare( "SELECT number,surname,firstname,position,job FROM player WHERE nummer IN ($qMarks)");         
$getPlayerData->execute($emptyNumbers);
Sign up to request clarification or add additional context in comments.

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.