更新mysql php pdo无法正常工作

时间:2016-02-20 12:36:27

标签: php mysql pdo

我正在尝试使用MySQL PHP PDO中的update语句更新我的数据库。但是,它返回错误:

SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配

有人能告诉我哪里出错了吗?

我的代码是:

$sqlupd = "UPDATE 'vendorprof'
    SET 'vd_loc_add1' = :Add1,
    'vd_loc_add2' = :Add2,
    'vd_loc_city' = :City,
    'vd_loc_state' = :State,
    'vd_cont_per' = :ContPerson,
    'vd_cont_mob' = :Mobile,
    WHERE 'vd_user_id' = :userid2";

$profileupd = $conn->prepare($sqlupd);
$profileupd->bindParam(":Add1",$Add1);
$profileupd->bindParam(":Add2",$Add2);
$profileupd->bindParam(":City",$City);
$profileupd->bindParam(":State",$State);
$profileupd->bindParam(":ContPerson",$ContPerson);
$profileupd->bindParam(":Mobile",$Mobile);

$profileupd->execute();
echo $profileupd->rowCount()."records updated Successfully";

1 个答案:

答案 0 :(得分:1)

嗯,显然你声明了7个参数标记,但只绑定了6.你是1参数标记短。

:Add1 // is bound as $Add1
:Add2 // is bound as $Add2
:City // is bound as $City
:State // is bound as $State
:ContPerson // is bound as $ContPerson
:Mobile // is bound as $Mobile
:userid2 // is bound ... not

此外,您的查询错误。您不要使用引号包装列名称。另外,你确实在WHERE之前加了一个逗号...它必须是:

$sqlupd = "UPDATE vendorprof
    SET vd_loc_add1 = :Add1,
    vd_loc_add2 = :Add2,
    vd_loc_city = :City,
    vd_loc_state = :State,
    vd_cont_per = :ContPerson,
    vd_cont_mob = :Mobile
    WHERE vd_user_id = :userid2";