0

Basically I'm trying to show a display message depending on if the row within a database was changed or not, I've looked around and it was suggested to use rowCount which I did, however it's still showing me the wrong output

function makeActive() { try{ $database = new Database; $text = ""; $activecode = $_GET["activecode"]; $setActive = "UPDATE username SET active = '1', activecode = 'Active' WHERE activecode = :activecode"; $stmt = $database->query($setActive); $database->bind(':activecode', $activecode); $database->execute(); $update = $database->rowCount(); if ($update === 1) { return $text .="Your account is now active" . "<br><a href='index.php'>Home page</a>"; } else { return $text .="Your account is already active" . "<br><a href='index.php'>Home page</a>"; } } catch(Exception $e ) { return $text .= "Something went wrong contact site administrator" . "<br><a href='index.php'>Login page</a>"; header( "refresh:10; url=index.php" ); } } 

So basicaly what should happen is if a row is updated, it should display return $text .="Your account is now active" . "<br><a href='index.php'>Home page</a>";

Added database class

class Database { private $host = "localhost"; private $user = "root"; private $pass = ""; private $dbname = "got"; private $dbh; private $error; private $stmt; public function __construct() { //SET DSN $dsn = "mysql:host=". $this->host . ";dbname=" . $this->dbname; $options = array ( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE =>PDO::ERRMODE_EXCEPTION ); //create PDO try { $this->dbh = new PDO($dsn, $this->user, $this->pass, $options); } catch(PDOEception $e) { $this->error = $e->getMessage(); } } public function query($query) { $this->stmt = $this->dbh->prepare($query); } public function bind($param, $value, $type = null) { if(is_null($type)) { switch(true) { case is_int($value): $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; case is_null($value): $type = PDO::PARAM_NULL; break; default: $type = PDO::PARAM_STR; } } $this->stmt->bindValue($param, $value, $type); } public function execute() { return $this->stmt->execute(); } public function lastInsertId() { $this->dbh->lastInsertId(); } public function rowCount() { $this->stmt->rowCount(); } public function connect() { $this->dbh->connect(); } public function resultset() { $this->execute(); return $this->stmt->fetchAll(PDO::FETCH_ASSOC); } } 
0

1 Answer 1

1

Here it is the problem:

Replace the method:

public function rowCount() { $this->stmt->rowCount(); } 

with this:

public function rowCount() { return $this->stmt->rowCount(); } 
Sign up to request clarification or add additional context in comments.

3 Comments

Ahh, you're a star and I can go to bed it's 02:35 here Thank you :)
You are welcome. Glad to have helped you. By me it's one hour later :-) Cakeman, for your project, if it helps you: my db adapter class. It's in the "EDIT" part of the answer. Bye.
I will look when i wake up, I've book marked it otherwise I won't sleep at all lol

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.