What's wrong with this?

$db = new mysqli("DBserver","username","password","database");
if ($db->connect_error) {
    die('Connect Error ('.$db->connect_errno.')'.$db->connect_error);

class registerInvitedUser {
    protected $formdata = array();
    protected $connection;
    protected $execute;
    protected $results;
    protected $response_code = "";
    protected $response_msg = "";

    public function __construct($db)
    {
        $this->connection = $db;
    }

    $this->execute = $this->connection->query("UPDATE `users` SET acctstatus= 'A' WHERE email = '".$formdata["email"]."'");
    $this->results = $this->execute->affected_rows;
    if ($this->results == 1) {
       $echo "user updated!";
       $this->response_code = '0';
       $this->response_msg .= 'Your account has successfully been created!  You may now <A HREF="loginform.php">click here</A> to log in with your username and password';
    }
}

The query executes and successfully updates the database, but the affected_rows conditional isn't getting tripped, and I haven't been able to figure out why.

Thanks for any suggestions you guys might have!

Member Avatar for diafol

Looks like something missing. All code should be wrapped up in methods, but you seem to have "naked code" within the class. This ain't allowed.

Seems your class is wrapped up n the conditional too. You sure this is right. Not really the way to code a class. Use an include yes by all means, but not the bare class in a conditional.

Try changing $this->results = $this->execute->affected_rows; into $this->results = $this->connection->affected_rows;

Thanks lps! That took care of it!

I'll get what you're suggesting, diafol - I was a little rushed when I put my post together, so I just had to make sure I included the part where I knew the script was failing.

Thank you both for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.