tags:

views:

122

answers:

5

I asked Google to help me I got no luck. :-( Here's the particular code that generates the error:

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

The whole function is the following:

    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 have missed something stupid. Can anyone tell me what's causing the problem please???

+1  A: 

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

while ($row = mysql_fetch_assoc($result)) {
    echo $row["usr"];
}
Luis Melgratti
A: 

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

webdestroya
A: 
$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);
Phill Pafford
+3  A: 

The problem is that $uname is an object, not a string. You need to call one of $uname's 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"]."'");

    }

}

that should do it (or one of the above solutions).

wash
EDIT: ^ that is assuming your code doesn't break if more than one row is returned in the result of the first query. It's probably not a bad idea to call $uname->num_rows() at some point. Better yet, modify the MySQL table, making a new bool column instead of setting confirm='yes', and then make the confirm column unique.
wash
A: 

Wow. Thanks for all the reply... I really love this site! I wish I can vote up already.. Thanks again! :-)

Joann