Mysqli_result class object cannot be converted to string

I asked Google to help me, I was out of luck. :-( Here is the specific code that generates the error:

$this->conn->query("UPDATE tz_members SET confirm='yes' WHERE usr='".$uname."'"); 

The whole function is as follows:

  function update_confirm_field($code) { $uname = $this->conn->query("SELECT usr FROM tz_members WHERE confirm='".$code."'"); $this->conn->query("UPDATE tz_members SET confirm='yes' WHERE usr='".$uname."'"); } 

Forgive me if I missed something stupid. Can someone tell me what is causing the problem, please?

+4
source share
4 answers

The problem is that $ uname is an object, not a string. You need to call one of the $ uname methods to access the data.

  function update_confirm_field($code) { $uname = $this->conn->query("SELECT usr FROM tz_members WHERE confirm='".$code."'"); while ($row = $uname->fetch_assoc()) { $this->conn->query("UPDATE tz_members SET confirm='yes' WHERE usr='".$row["usr"]."'"); } } 

who should do this (or one of the above solutions).

+6
source

The $ uname returned by your first request is a mysql_result object, not a string. you must get data from this result in order to use it in the second query.

 while ($row = mysql_fetch_assoc($result)) { echo $row["usr"]; } 
+1
source

The query method returns a pointer / object to the result of the query, it does not just dump the response directly. You need to do something like list($uname) = $uname->fetch_row;

0
source
 $updateQuery = "UPDATE tz_members SET confirm='yes' WHERE usr= (SELECT usr FROM tz_members WHERE confirm='".$code."')"; // Get name and update in the same query $this->conn->query($updateQuery); 
0
source

Source: https://habr.com/ru/post/1309597/


All Articles