开发者

MySQL Query: Trying to get property of non-object

I'm getting following error message.

Notice: Trying to get property of non-object in
C:\xampp\htdocs\my\include\user_functions.php on line 34

Here is my Code

$conn = db_connection();
    if($conn == false) {
        user_error('Unable to connect to database');
        return false;
    }
    $query = "UPDATE user SET passwd = '".$new_passwd."'
            WHERE username = '".$username."'  ";

    $result=$conn->query($query);
    if($result == false) {
        user_error('Query Error'.$conn->error);
        return false;
    }           

    if($result->num_rows == 1) {
        echo 'Password changed';
    } else {
            echo 'Failed ';
    }

here is my db_connection

function db_connection() {
    $db = new mysqli('localhost','root','','php_login');
    if(!$db) {
        echo 'Could not connect to database server';
    } else {
        return $db;
 开发者_开发问答   }
}


The UPDATE statement doesn't return a result set. What are you trying to get from fetch_array?


UPDATE

class mysqli{

    public $aff_num_rows;
    //some properties
    //some properties

    //some methods
    //some methods

    public function query($sql)
    {
        $resultset = mysql_query($sql); //after query instantiate the $aff_numrows
                        //property with function 
        $this->aff_num_rows = mysql_affected_rows(); //guess you are using sqlite
        //so you might have different function
        //and you can use this property 
    }   

}

And in you code you have

if($conn->aff_num_rows == 1) {
    echo 'password changed';
} else {
        echo 'error changing pasword';
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜