Well I'm working on insert a user into a database, I could swear I've been here before...

error

<b>Fatal error</b>:  Call to undefined method Database::bindValue()
try
		{
			$db = new Database;
			$success = ["message" => "Please check your Email address to activate your account"];	
			$db->prepare('INSERT INTO username (username, password, email, profileImg, profileImgPath, profileImgType, accountStatus, verified, joined)
			VALUES
			(:username, :password,:activationCode, :email, :filename, :filepath, :filetype, 0, NOW())');
			$db->bindValue(':username', $username);
			$db->bindValue(':email', $email);
			$db->bindValue(':password', password_hash($post['password'], PASSWORD_DEFAULT));
			$db->bindValue(':activationCode', $activationCode);
			$db->bindValue(':filename', $filename);
			$db->bindValue(':filepath', $filepath);
			$db->bindValue(':filetype', $filetype);
			$db->execute();
			$code = 'https://gotsocial.co.uk/gotsocial/active.php?activecode=' . $activationCode . '. 
                ';
			$to = $post['email'];
			$subject = 'GOT Social';
			$from = "register@gotsocial.co.uk";
			$result = mail($to, $subject, $code, "From: $from");
		}
		catch(Exception $e)
			{
				$errors[] = ["name" => "username", "error" => "Username or E-mail may already be registered"];
			}	

}	  

<?php
class Database extends PDO

{
    private $host = 'localhost';
    private $user = 'root';
    private $pass = '';
    private $dbname = 'shops';

public function __construct($host = null, $user = null, $pass = null, $opts = null)
{
    parent::__construct("mysql:host={$this->host};dbname={$this->dbname}", $this->user, $this->pass, $opts);
    $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
}

    ...After making sure it did, in fact, return a PDOStatement object and not a Boolean false. 😉

      try
      		{
      			$db = new Database;
      			$success = ["message" => "Please check your Email address to activate your account"];	
      			$process = $db->prepare('INSERT INTO users (username, password, email, profileImg, profileImgPath, profileImgType, accountStatus, verified, joined)
      			VALUES
      			(:username, :password,:activationCode, :email, :filename, :filepath, :filetype, 0, NOW())');
      			$process->bindValue(':username', $username);
      			$process->bindValue(':email', $email);
      			$process->bindValue(':password', password_hash($post['password'], PASSWORD_DEFAULT));
      			$process->bindValue(':activationCode', $activationCode);
      			$process->bindValue(':filename', $filename);
      			$process->bindValue(':filepath', $filepath);
      			$process->bindValue(':filetype', $filetype);
      			$process->execute();
      			$code = 'https://gotsocial.co.uk/gotsocial/active.php?activecode=' . $activationCode . '. 
                      ';
      			$to = $post['email'];
      			$subject = 'GOT Social';
      			$from = "register@gotsocial.co.uk";
      			$result = mail($to, $subject, $code, "From: $from");
      		}
      		catch(Exception $e)
      			{
      				$errors[] = ["name" => "username", "error" => "Username or E-mail may already be registered"];
      			}	
      
      

      ...After making sure it did, in fact, return a PDOStatement object and not a Boolean false.

      You mean add in finally? Or hm?

        cluelessPHP;11064711 wrote:
        ...
        You mean add in [URL="https://adayinthelifeof.nl/2013/02/12/php5-5-trycatchfinally/"]finally[/URL]? Or hm?[/QUOTE]
        
        That depends on your PDO config, I guess. If you've set it up to throw a PDOException on errors, then you can use whatever try/catch methodology you prefer. If not, then you'd have to explicitly test what it returns.
          Write a Reply...