我收到此错误: 警告:PDOStatement :: execute():SQLSTATE [HY093]:参数号无效:参数未在
中定义数组([0] => HY093 [1] => [2] =>)
$arr = array();
$values = "";
$sql = "INSERT INTO avisos(nombre ";
$values.=":nombre";
$arr[] = "nombre => $nombre";
if($plataforma!=""){
$sql .= ", idPlataforma";
$values.=", :idPlataforma";
$arr[] = "idPlataforma => $plataforma";
}
if(idCompania!=""){
$sql .= ", idCompania";
$values.=", :idCompania";
$arr[] = "idCompania => $compania";
}
if($fondo!=""){
$sql .= ", idFondo";
$values.=", :idFondo";
$arr[] = "idFondo => $fondo";
}
if($remitente != ''){
$sql .= ", idRemitente";
$values.=", :idRemitente";
$arr[] = "idRemitente => $remitente";
}
$sql.= ") VALUES ($values);";
$stmt = $con->prepare($sql);
if ($stmt->execute($arr)){
echo "OK";
}
我无法看到我失败的地方。
答案 0 :(得分:3)
您发送到execute()
的数组需要具有键值对,其中键是占位符,值是您要插入的值。
所以而不是:
$arr[] = "nombre => $nombre";
你需要:
$arr[':nombre'] = $nombre;
或:
$arr['nombre'] = $nombre;
等