2014-04-01 6 views
-2

PDO를 사용하여 select에 이상이 생겨서 여기에 귀하의 도움을 요청했습니다.PDO 유효하지 않은 매개 변수 번호 : 매개 변수가 정의되지 않았습니다.

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: 
parameter was not defined in `$verifyUser->execute();` 

ideia가 왜이 일이 될 수 있습니다 누군가 : 나는이 아래의 코드와 필자는이 오류을 받고있다?

내 PHP는 코드 : bindValue 당신이 :id를 사용하는 동안

if(!$_SESSION['result']) 
{ 
    header('Location: index.php'); 
} 
else 
{ 
    $userId = $_SESSION['result']['id'];     
    $verifyUser = $pdo->prepare("SELECT * FROM aadmins where id = :userId"); 
    $verifyUser->bindValue(":id", $userId); 
    $verifyUser->execute(); 
    $num_rows = $verifyUser->rowCount(); 
    $result = $verifyUser->fetch(PDO::FETCH_ASSOC); 
} 
+5

귀하의 자리 표시자는': userId'이지만 당신은': id'를 바인딩하고 있습니다. 대신'bindValue()'에': userId'를 바인드하십시오. –

답변

3

당신은, SQL 쿼리에 :userId을 사용하고 있습니다.

$verifyUser = $pdo->prepare("SELECT * FROM aadmins where id = :userId"); 
$verifyUser->bindValue(":id", $userId); 

그러나 쿼리와 bindvalue는 같아야합니다.

$verifyUser = $pdo->prepare("SELECT * FROM aadmins where id = :id"); 
$verifyUser->bindValue(":id", $userId); 
+1

감사 ... 문제가되었습니다! 나는 내가 그것을 어떻게 didnt하는지에 관해 안다, 나는 내가 많은 시간 LOL 후에 튀긴 머리를 가지고있다라고 생각한다! 감사합니다 :) – John23

+0

당신이 볼 때 그렇게 분명해. – AdRock

관련 문제