Invalid parameter number(SQLSTATE[HY093])。

huangapple go评论83阅读模式
英文:

SQLSTATE[HY093] Invalid parameter number

问题

我有这个SQL语句:

try {
    $sql = $db->prepare('INSERT INTO customers (UID, kundennr, salutation, fname, 
           lname, organization, email, phone, address, zip, city, CHECKED)

VALUES (:uid, :kundennr, :salutation, :fname, :lname, :organization, :email, :phone, :address, :zip, :city, CHECKED)');
    
    
    $sql->execute( array( 
        ":uid"                  => 0,
        ":kundennr"             => $customerNumber,
        ":salutation"           => $salutation,
        ":fname"                => $fname,
        ":lname"                => $lname,
        ":organization"         => $organization,
        ":email"                => serialize($emails),
        ":phone"                => serialize($phones),
        ":address"              => $address,
        ":zip"                  => $zip,
        ":city"                 => $city,
        ":checked"              => $checked
    ));
    
} catch (PDOException $e) {    
    echo $e->getMessage();
}

但我收到了这个错误:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

我的错误在哪里?

英文:

I have this sql statement:

try {
    $sql = $db->prepare( 'INSERT INTO customers (UID, kundennr, salutation, fname, 
           lname, organization, email, phone, address, zip, city, CHECKED)

VALUES (:uid, :kundennr, :salutation, :fname, :lname, :organization, :email, :phone, :address, :zip, :city, CHECKED)');
		
		
    $sql->execute( array( 
	    ":uid"					=> 0,
 	    ":kundennr" 			=> $customerNumber,
	    ":salutation" 			=> $salutation,
	    ":fname" 				=> $fname,
	    ":lname" 				=> $lname,
	    ":organization" 		=> $organization,
	    ":email" 				=> serialize($emails),
	    ":phone" 				=> serialize($phones),
	    ":address" 			    => $address,
	    ":zip" 					=> $zip,
	    ":city" 				=> $city,
	    ":checked" 				=> $checked
    ));
		
} catch (PDOException $e) {	
	echo $e->getMessage();
}

But I get this error:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

Where is my mistake???

答案1

得分: 2

你最后的数值被命名为 checked,但你正在使用键名为 :checked 执行查询。请更改其中一个,使它们的名称匹配。

英文:

Your last value is named checked but you are executing the query with the key named :checked. Change one of them, so that the names match.

答案2

得分: 1

在"VALUES"前面缺少了冒号(:)。

使用以下SQL查询:

$sql = $db->prepare('INSERT INTO customers (UID, kundennr, salutation, fname, 
           lname, organization, email, phone, address, zip, city, CHECKED)
VALUES (:uid, :kundennr, :salutation, :fname, :lname, 
        :organization, :email, :phone, :address, :zip, :city, :checked)');
英文:

In VALUES you have missed colon ahead of checked

Use the below sql query:

$sql = $db->prepare( 'INSERT INTO customers (UID, kundennr, salutation, fname, 
           lname, organization, email, phone, address, zip, city, CHECKED)
VALUES (:uid, :kundennr, :salutation, :fname, :lname, 
        :organization, :email, :phone, :address, :zip, :city, :checked)');

huangapple
  • 本文由 发表于 2023年1月9日 01:16:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定