SQLSTATE [HY093]无效的参数号,所有的参数相匹配
问题描述:
我有这样的代码SQLSTATE [HY093]无效的参数号,所有的参数相匹配
switch ($var1) {
case 'corredor':{
$query = ' UPDATE corredor
SET
cedula = :cedula,
nombres = :nombres,
apellidos = :apellidos,
fechanacimiento = :fechanacimiento,
telefono = :telefono,
correo = :correo,
direccion = :direccion,
fecharegistro = :fecharegistro,
estatus = :estatus,
aseguradora_rif =: aseguradora_rif
WHERE cedula = :cedula_old
';
$query_params = array(
':cedula' => $_POST['cedula'],
':nombres' => $_POST['nombres'],
':apellidos' => $_POST['apellidos'],
':fechanacimiento' => $_POST['fechanacimiento'],
':telefono' => $_POST['telefono'],
':correo' => $_POST['correo'],
':direccion' => $_POST['direccion'],
':fecharegistro' => $_POST['fecharegistro'],
':estatus' => $_POST['estatus'],
':aseguradora_rif' => $_POST['aseguradora_rif']
':cedula_old' => $var2
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch (PDOException $ex) {
$ex->getMessage();
}
#header('Location: index.php?do=listacorredor');
break;
} //fin case
我越来越
SQLSTATE [HY093]:无效的参数编号:绑定变量的数目不令牌
,我不知道为什么,我所有的参数都是符合的匹配号码,我已经找了额外的,在查询的末尾,而params所有的绑定匹配数据B因为我在这里输了,其他的答案是失踪的东西,或类似的东西,但真的不能在这里看到问题。
答
您忘记绑定PARAMS :)
http://php.net/manual/es/pdostatement.bindparam.php
http://php.net/manual/es/pdostatement.bindvalue.php
之前,你需要 “分配” 值数据对应到数组。
例:
$stmt = $db->prepare($query);
$stmt->bindParam(':cedula', $_POST['cedula']);
$result = $stmt->execute();
+0
让我建议你只回答你有经验的地区 –
你有后多余的逗号' ':cedula_old'=> $ VAR2,',没有上面的线。 – Qirel
哦是的,我正在测试,同时发布这个,如果删除,我仍然得到相同的错误。 –
'aseguradora_rif =:aseguradora_rif'你在这里有一个额外的空间 –