可恢复的致命错误:无法将 PDOStatement 类的对象转换为字符串

乔丹男爵

我正在尝试使用 PHP 将数据发送到数据库,但是当我使用执行查询时,execute()我收到一个错误消息

可恢复的致命错误:第 12 行的 C:\xampp\htdocs\Code Sharing Website\submit_snippet.php 中的类 PDOStatement 的对象无法转换为字符串

这是我的代码

include 'includes/db.php';

if(isset($_POST['title']) && isset($_POST['snippet'])) {
  $title = $_POST['title'];
  $snippet = $_POST['snippet'];

  $snippet = $db->prepare("INSERT INTO all_snippets (snippet_name, snippet_body) VALUES (:title, :snippet)");
  $snippet->execute(array(
    ':title' => $title,
    ':snippet' => $snippet
  ));
} else {
  echo "Error: Please fill out all fields";
}
马威尔

您正在将snippet变量重新分配给 PDO 对象,然后尝试在execute. 这些变量之一需要重命名。

更改$snippet = $_POST['snippet'];$snippetPost = $_POST['snippet'];和你execute的这个应该可以解决它。

  $snippet->execute(array(
    ':title' => $title,
    ':snippet' => $snippetPost
  ));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

可恢复的致命错误:类 PDOStatement 的对象无法转换为字符串 PHP 错误消息

致命错误:无法转换类PDOStatement的对象

类 PDOStatement 的对象无法转换为字符串 - 获取下拉列表以动态显示数据

如何解决“可恢复的致命错误:类Closure的对象无法在...中转换为字符串”

插入查询结果为“可恢复的致命错误:mysqli 类的对象无法转换为字符串”

如何修复注意:类 PDOStatement 的对象无法转换为 int

Php 函数错误(类 PDOStatement 的对象)

可捕获的致命错误:无法将 AppBundle\Entity\Location 类的对象转换为字符串

Symfony 2可捕获的致命错误:无法将类UserCategory的对象转换为字符串

可捕获的致命错误:无法将MongoCursor类的对象转换为字符串

PHP,可捕获的致命错误:无法将mysqli类的对象转换为字符串

无法将对象类转换为字符串错误

无法将类stdClass的对象转换为字符串

Doctrine:无法将类的对象转换为字符串

wpdb类的对象无法转换为字符串

PHP-类的对象无法转换为字符串

类stdClass的对象无法转换为字符串-Laravel

类集的对象无法转换为字符串

类stdClass的对象问题无法转换为字符串

php类DateInterval的对象无法转换为字符串

Symfony 3类的对象无法转换为字符串

类stdClass的对象无法转换为字符串CodeIgniter

php类Closure的对象无法转换为字符串

ZipArchive类的对象无法转换为字符串

“类stdClass的对象无法转换为字符串”php

类 stdClass 的对象无法转换为字符串 (php)

将类的对象转换为字符串

将字符串转换为类对象

将字符串转换为Python类对象?