[英]Cannot use object of type PDOStatement as array in
I have this Error: Fatal error: Uncaught Error: Cannot use object of type PDOStatement as array in C:\xampp\htdocs\seth\Plugins\login\php\completedetails.php:28 Stack trace: #0 {main} thrown in C:\xampp\htdocs\seth\Plugins\login\php\completedetails.php on line 28 I have this Error: Fatal error: Uncaught Error: Cannot use object of type PDOStatement as array in C:\xampp\htdocs\seth\Plugins\login\php\completedetails.php:28 Stack trace: #0 {main} thrown in C:\xampp\htdocs\seth\Plugins\login\php\completedetails.php 在第 28 行
it some days ago was functiones but now it pass, ¿what I should do?, Im leaving the code down几天前它是功能,但现在它通过了,¿我应该做什么?,我留下了代码
session_start();
$_SESSION['id'];
$id = $_SESSION['id'];
$name = $_POST['name'];
$password = $_POST['password'];
$password = password_hash($password, PASSWORD_DEFAULT);
$team = $_POST['team'];
if($name == "" && $password == "" && $team == ""){
return false;
}
else {
require './conectar.php';
$resultset = $conn->prepare("SELECT * FROM users WHERE id = '$id' LIMIT 1");
$resultset->execute();
$resultkey = $resultset->fetch();
if($resultkey !== false) {
$update = "UPDATE users SET name = :name, password = '$password' WHERE id = '$id' LIMIT 1";
$up = $conn->prepare($update);
$up->bindParam(':name', $_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS);
$up->execute();
$_SESSION['name'] = $up['name'];
}
} }
You need to first fetch the result of your query:您需要首先获取查询结果:
$up = $conn->prepare($update);
$up->bindParam(':name', $_POST['name'], FILTER_SANITIZE_SPECIAL_CHARS);
$up->execute();
$result = $up->fetch();
$_SESSION['name'] = $result['name'];
The fetch
method in your framework might return an object instead of an array.框架中的
fetch
方法可能会返回 object 而不是数组。 In that case you can access the name property like this:在这种情况下,您可以像这样访问 name 属性:
$result->name;
Either way, you can't use $up
to get the name because, as your error says, it's an object of type PDOStatement and not actually the result of the query.无论哪种方式,您都不能使用
$up
来获取名称,因为正如您的错误所说,它是 PDOStatement 类型的 object 而实际上不是查询的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.