2013-10-24 20:21
浏览 42

PDO:参数号无效:未定义参数。 但我有所有的领域?

I'm having trouble with this insert statement. It is inside an if statement and used after a user successfully uploads and image.

                $contenido = $filename;
                $db = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
                $data = $db->prepare("INSERT INTO publicaciones (autorID, autorNombre, nombre, claseDeContenido, contenido, palabras, etiquetas, fecha) VALUES (:autorID, :autorNombre, :nombre, :claseDeContenido, :contenido, :palabras, :etiquetas, :fecha)");
                $data->execute(array( ':autorID,' =>$autorID,
                            ':autorNombre' =>$autorNombre,
                            ':nombre' => $nombre,
                            ':claseDeContenido' => $claseDeContenido,
                            ':contenido' => $contenido,
                            ':palabras' =>$palabras,
                            ':etiquetas' => $etiquetas,
                            ':fecha' => $fecha));

The error is

PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in .... on line 215

But there is no change of that variable name within the script, there are eight parameters to insert and I am sending 8. I have checked and $fecha, which is on line 215, is definitely being sent.

What could it be?

None of this function is run without all fields being present in their respective variables.

if($autorID !== '' || $autorNombre !== '' || $nombre !== '' || $claseDeContenido !== '' || $contenido !== '' || $palabras !== '' || $etiquetas !== '' || $fecha !== '')

NOTE: The image is uploading succesfully

图片转代码服务由CSDN问答提供 功能建议

我在使用此插入语句时遇到问题。 它位于if语句中,在用户成功上载和映像后使用。

  $ contenido = $ filename; 
 $ data = $ db-> prepare(“INSERT INTO”  publicaciones(autorID,autorNombre,nombre,claseDeContenido,contenido,palabras,etiquetas,fecha)VALUES(:autorID,:autorNombre,:nombre,:claseDeContenido,:contenido,:palabras,:etiquetas,:fecha)“); 
 $  data-> execute(array(':autorID,'=> $ autorID,
':autorNombre'=> $ autorNombre,
':nombre'=> $ nombre,
':claseDeContenido'=  > $ claseDeContenido,
':contenido'=> $ contenido,
':palabras'=> $ palabras,
':etiquetas'=> $ etiquetas,
':fecha'=>  $ fecha)); 


  PDOStatement :: execute():SQLSTATE [HY093]  :参数号无效:p  arameter没有在第215行中定义

但是脚本中的变量名没有变化,要插入8个参数 我发送了8.我已经检查了 $ fecha ,这是 215 ,肯定是在发送。


如果没有相应变量中存在所有字段,则不会运行此函数。 \ n

  if($ autorID!==''|| $ autorNombre!==''|| $ nombre!==''|| $ claseDeContenido!==''|| $ contenido!==  ''|| $ palabras!==''|| $ etiquetas!==''|| $ fecha!=='')


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dsgsdg206050 2013-10-24 20:25

    You have a superfluous comma in the reference to :autorID:

                    $data->execute(array( ':autorID,' =>$autorID,
    //                                             ^--- remove this comma
    打赏 评论
  • dongshetao1814 2013-10-24 20:26

    is not defined


    is, however.

    You separate column names with commas but the comma can not be a part of the column name in the array you execute on the query.

    Do this:

    $data->execute(array( ':autorID' =>$autorID

    instead of

    $data->execute(array( ':autorID,' =>$autorID

    And your code will run fine.

    打赏 评论
  • doujuanju3076 2013-10-24 20:26

    But I have all the fields?

    You have not.

    "parameter was not defined" means you are trying to bind a parameter that weren't defined in the query. So, you need to double check your query. Yourself. Without asking someone else to do it for you.

    打赏 评论

相关推荐 更多相似问题