【发布时间】:2020-09-11 01:36:39
【问题描述】:
PHP:
$selquery = $con->prepare("SELECT * FROM bookdetails WHERE id = :id");
$selquery->bindParam(":id",$bookid);
$selquery->execute();
$selresult = $selquery->fetchAll(PDO::FETCH_ASSOC);
$bookname = $selresult['name'];
$image = $selquery['image'];
错误:
注意:C:\xampp\htdocs\libraryportal\studentissueclass.php 第 54 行中的未定义索引:名称
致命错误:未捕获错误:不能在 C:\xampp\htdocs\libraryportal\studentissueclass.php:55 中使用 PDOStatement 类型的对象作为数组 堆栈跟踪:#0 C:\xampp\htdocs\libraryportal\issueBooklist.php(20): Studentissue->displayList() #1 {main} 抛出 C:\xampp\htdocs\libraryportal\studentissueclass.php 第 55 行
【问题讨论】:
-
大约一个小时前提出的上一个问题的重复(措辞不同),我们要求在 var_dump 上返回值,以便我们可以看到您的名称索引问题出在哪里。我们还建议进行 fetch 而不是 fetchAll()...
标签: php pdo backend htdocs pdostatement