可捕获的致命错误:mysqli类的对象无法转换为字符串 [英] Catchable fatal error: Object of class mysqli could not be converted to string

查看:52
本文介绍了可捕获的致命错误:mysqli类的对象无法转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个问题,我是PHP的新手,并且在更新数据库上的字符串时遇到问题,它抛出了以下错误:可捕获的致命错误:mysqli类的对象无法在第11行的C:\ xampp \ htdocs ...... \ ban.php中转换为字符串

So I have a bit of a problem, I'm EXTREMELY new to PHP and I'm having a problem updating a string on my database, It's throwing out this error: Catchable fatal error: Object of class mysqli could not be converted to string in C:\xampp\htdocs......\ban.php on line 11

以下是来源:

<?php
$servername = "localhost";
$username = "example";
$password = "example";
$name = "Brendan";

// Create connection
$conn = new mysqli($servername, $username, $password);
$query = mysqli_query("$conn, UPDATE * wp_oxygenpurchaseusers
                  SET user_url =  '2'
                  WHERE display_name = $name");
                    while ($row = $result->fetch_assoc()) {
                        echo $row['classtype']."<br>";
}
?>

在此先感谢大家的帮助:)

Thanks in advance for everyone's help :)

推荐答案

您的代码有几个问题.

There are several problems with your code.

  • 首先,您要分配变量$query,但是在尝试获取结果时使用$result.
  • 第二,您在查询中包括了连接($conn).它需要分开.
  • 最后,您可能需要用引号将值引起来.

  • First of all, you are assigning the variable $query, but using $result when trying to fetch the result.
  • Secondly, you have included your connection ($conn), inside your query. It needs to be separated.
  • Finally, you probably need to put quotes around your value.

$result = mysqli_query($conn, "UPDATE * wp_oxygenpurchaseusers
                   SET user_url =  '2'
                   WHERE display_name = '$name'");

如果user_url始终是数字,则应该将其真正转换为类型INT而不是使用字符串.

If user_url is always a number, you should really convert it to type INT instead of using a string.

这篇关于可捕获的致命错误:mysqli类的对象无法转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆