英文:
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)');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论