Php 错误:类mysqli的对象无法转换为字符串
我知道这个问题在这个平台上被问了好几次,但是没有一个能解决我的问题 我从下面的代码中得到这个错误Php 错误:类mysqli的对象无法转换为字符串,php,mysql,mysqli,Php,Mysql,Mysqli,我知道这个问题在这个平台上被问了好几次,但是没有一个能解决我的问题 我从下面的代码中得到这个错误 //This is working $edition=mysqli_query($con,"select Price from books where Name='$book'"); //This is showing an error. The query is working when I run it on phpmyadmin. //$edition=mysqli_query($con,"
//This is working
$edition=mysqli_query($con,"select Price from books where Name='$book'");
//This is showing an error. The query is working when I run it on phpmyadmin.
//$edition=mysqli_query($con,"select Price from books where Name='$book' and Edition='$edition'");
//I am using mysqli_fetch_assoc to store it in $row and use the answer for later.
$row = mysqli_fetch_assoc($edition);
让我知道问题和解决方案。提前感谢。:) 那我们开始吧:)
考虑到在您的工作示例中已经使用了变量
$book
,我的赌注是唯一的其他变量$edition
。我在想,如果您可以调试代码并在使用它进行查询之前检查分配给它的值,您可以确认它是否是可接受的类型。将$book
设置为什么?表单从用户处获取图书名称并将其保存在$book中。$book工作正常,存储的值$edition不正确,您需要字符串,但在代码的某个地方,它会被一个对象占用,只需回溯跟踪它并找到它的更改位置。另一种方法是调试代码,并在使用它生成代码之前检查其值query@Ali,我弄错了。你说得对非常感谢!我可以建议@Ali将答案发布为下面的答案,以便用户134179将其标记为已接受吗?