[英]Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
I'm getting an我得到一个
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined"... PDOStatement->execute() #1 {main} thrown on line 61. Line 61 being $stmt->execute();
致命错误:未捕获的 PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined"... PDOStatement->execute() #1 {main} 在第 61 行抛出。第 61 行是 $stmt->execute();
$add_joke = filter_input(INPUT_POST, 'add_joke');
if ($add_joke != NULL){
$actual_date = date('Y-m-d');
$actual_id = null;
$sql = 'INSERT INTO joke (id, JokeText, Joke Date) VALUES (:id, :JokeText, :Joke Date)';
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $actual_id);
$stmt->bindParam(':JokeText', $add_joke);
$stmt->bindParam(':Joke Date', $actual_date);
$stmt->execute();
}
Are you using MySQL?您使用的是 MySQL 吗? Anyway, try to change code for actual_id: change it to 0 or remove it from query and specify it as an auto increment primary key in your table.
无论如何,尝试更改 actual_id 的代码:将其更改为 0 或将其从查询中删除并将其指定为表中的自动增量主键。 If you really meant to add NULL value (for any reason), just remove it form query and make table field nullable.
如果您真的想添加 NULL 值(出于任何原因),只需将其从查询中删除并使表字段可为空。
Also not sure if you can use space in ':Joke Date'也不确定您是否可以在“:笑话日期”中使用空格
Finally, not a great idea to use anything like最后,使用类似的东西不是一个好主意
if ($add_joke != NULL)
in PHP code在 PHP 代码中
The Likely issue is your use of 'Joke Date' which has a space in it.可能的问题是您使用了其中有空格的“笑话日期” 。
Your naming seems a little confused.你的命名似乎有点混乱。 You can either change Joke Date to JokeDate or Joke_Date or joke_date or simply date or date_created depending upon your naming conventions.
您可以将 Joke Date 更改为 JokeDate 或 Joke_Date 或 joke_date 或只是 date 或 date_created,具体取决于您的命名约定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.