2017-04-21 14 views
-2

上記のエラーが発生します。ここではそれが起こっている私のセットアップです:'SQLSTATE [HY093]:無効なパラメータ番号:パラメータが定義されていません'

$InsertSQL = "insert into reports.NonVarassetInvoices(State, CLLI, Type, Vendor, DateReceived, InvoiceNumber, InvoiceDate, TotalInvoiceAmount, ProjectWONumber, CAF, SentForApprovalDate, Approver 
      , ApprovalReceivedDate, ReleaseDate, ReleaseNumber, SentToAPDate, InvoicerName, Status, HoldReason, Notes) 
select ':State', ':CLLI', (select Id from pmdb.PicklistChild where ParentId in(select Id from pmdb.PicklistParent where Value = ':Type') order by Sequence) 
    , ':Vendor', ':DateReceived', ':InvoiceNumber', ':InvoiceDate', :TotalInvoiceAmount, ':ProjectWONumber', ':CAF', ':SentForApprovalDate', ':Approver' 
    , ':ApprovalReceivedDate', ':ReleaseDate', ':ReleaseNumber', ':SentToAPDate', ':InvoicerName' 
    , (select Id from pmdb.PicklistChild where ParentId in(select Id from pmdb.PicklistParent where Value = ':Status') order by Sequence) 
    , (select Id from pmdb.PicklistChild where ParentId in(select Id from pmdb.PicklistParent where Value = ':HoldReason') order by Sequence), ':Notes'"; 

$stmt = $conn->prepare($InsertSQL); 

$stmt->bindParam(':State', $State, PDO::PARAM_STR); 
$stmt->bindParam(':CLLI', $CLLI, PDO::PARAM_STR); 
$stmt->bindParam(':Type', $Type, PDO::PARAM_INT); 
$stmt->bindParam(':Vendor', $Vendor, PDO::PARAM_STR); 
$stmt->bindParam(':DateReceived', $DateReceived, PDO::PARAM_STR); 
$stmt->bindParam(':InvoiceNumber', $InvoiceNumber, PDO::PARAM_STR); 
$stmt->bindParam(':InvoiceDate', $InvoiceDate, PDO::PARAM_STR); 
$stmt->bindParam(':TotalInvoiceAmount', $TotalInvoiceAmount, PDO::PARAM_INT); 
$stmt->bindParam(':ProjectWONumber', $ProjectWONumber, PDO::PARAM_STR); 
$stmt->bindParam(':CAF', $CAF, PDO::PARAM_STR); 
$stmt->bindParam(':SentForApprovalDate', $SentForApprovalDate, PDO::PARAM_STR); 
$stmt->bindParam(':Approver', $Approver, PDO::PARAM_STR); 
$stmt->bindParam(':ApprovalReceivedDate', $ApprovalReceivedDate, PDO::PARAM_STR); 
$stmt->bindParam(':ReleaseDate', $ReleaseDate, PDO::PARAM_STR); 
$stmt->bindParam(':ReleaseNumber', $ReleaseNumber, PDO::PARAM_STR); 
$stmt->bindParam(':SentToAPDate', $SentToAPDate, PDO::PARAM_STR); 
$stmt->bindParam(':InvoicerName', $InvoicerName, PDO::PARAM_STR); 
$stmt->bindParam(':Status', $Status, PDO::PARAM_INT); 
$stmt->bindParam(':HoldReason', $HoldReason, PDO::PARAM_INT); 
$stmt->bindParam(':Notes', $Notes, PDO::PARAM_STR); 

$stmt->execute(); 

私も、私は同じエラーを取得execute(array(':State => $State ...));をやって試してみました。

これは正確に何を意味するのかわかりませんが、私は似たような名前の他のいくつかの質問を見ました。私が正確な問題に答えないと言うことができる限り、

何か不足していますか?これをどうやって解決するのですか?

UPDATE

私は以下の回答に基づいて、私の挿入SQLを更新しました。今、私は500 Internal Server Errorメッセージと空白の画面を取得

$InsertSQL = "insert into reports.NonVarassetInvoices(State, CLLI, Type, Vendor, DateReceived, InvoiceNumber, InvoiceDate, TotalInvoiceAmount, ProjectWONumber, CAF, SentForApprovalDate, Approver 
                   , ApprovalReceivedDate, ReleaseDate, ReleaseNumber, SentToAPDate, InvoicerName, Status, HoldReason, Notes) 
        select :State, :CLLI, (select Id from pmdb.PicklistChild where ParentId in(select Id from pmdb.PicklistParent where Name = 'NonVInvoiceType') Value = :Type and IsActive = 1) 
         , :Vendor, :DateReceived, :InvoiceNumber, :InvoiceDate, :TotalInvoiceAmount, :ProjectWONumber, :CAF, :SentForApprovalDate, :Approver 
         , :ApprovalReceivedDate, :ReleaseDate, :ReleaseNumber, :SentToAPDate, :InvoicerName 
         , (select Id from pmdb.PicklistChild where ParentId in(select Id from pmdb.PicklistParent where Name = 'NonVStatus') and Value = :Status and IsActive = 1) 
         , (select Id from pmdb.PicklistChild where ParentId in(select Id from pmdb.PicklistParent where Name = 'NonVHoldReason') and Value = :HoldReason and IsActive = 1), :Notes"; 

。私はこのような実行ステートメントにParamsを置く場合:

$stmt->execute(array(':State'=>$State,':CLLI'=>$CLLI,':Type'=>$Type,':Vendor'=>$Vendor,':DateReceived'=>$DateReceived,':InvoiceNumber'=>$InvoiceNumber,':InvoiceDate'=>$InvoiceDate 
         ,':TotalInvoiceAmount'=>$TotalInvoiceAmount,':ProjectWONumber'=>$ProjectWONumber 
         ,':CAF'=>$CAF,':SentForApprovalDate'=>$SentForApprovalDate,':Approver'=>$Approver,':ApprovalReceivedDate'=>$ApprovalReceivedDate,':ReleaseDate'=>$ReleaseDate 
         ,':ReleaseNumber'=>$ReleaseNumber,':SentToAPDate'=>$SentToAPDate 
         ,':InvoicerName'=>$InvoicerName,':Status'=>$Status,':HoldReason'=>$HoldReason,':Notes'=>$Notes)); 

その後、私はこのエラーを取得する:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near 'Value'

+0

'値'の近くに構文が正しくありません –

+0

どうしたのですか?この例では、私が[ここ](http://php.net/manual/en/pdo.prepare.php)を見つけることに基づいて私の見た目が正しいと思う。 – Mike

+0

pdoの例はSQLの構文とは関係ありません。あなたはまずそれを学ぶことになっています。 –

答えて

0

あなたが実際にあなたのSQLステートメントのいずれかのパラメータを持っていません。あなたがそれらを引用しているとして、彼らはすべてのリテラル文字列です:

... where Value = ':Type' ... 
       ^ ^these need to go 

は、だから、プレースホルダを囲むこれらすべての単一引用符を削除する必要があります。

など列名、テーブル名、のため別にあなただけの値のプレースホルダを使用できることからしていない

だから、これは引用符なしで機能しません、次のいずれかの変数の場合は

... select ':State', ':CLLI' ... 

文字列に挿入する必要があり、SQLインジェクションを避けるためには、まずホワイトリストと照合する必要があります。

// check all column names agains a white-list 
... 
// insert them into your string 
... select `{$State}`, `{$CLLI}` ... 
// etc. 
+0

これは私を助け、私を再び動かしました。私はまだこれが動作している今修正する必要がある他の問題がまだあります。 – Mike

関連する問題