Jump to content

so hey guys im creating a login script in php for my website and i keep receiving this error

( ! ) Fatal error: Call to undefined method DB::results() in D:\programs\wamp\www\ooplr\index.php on line 9 Call Stack # Time Memory Function Location 1 0.0006 242248 {main}( ) ..\index.php:0

here is the code for index

<?phprequire_once 'core/init.php';$user = DB::getInstance()->get('users', array('username','=','alex'));if(!$user->count()) {	echo 'No user';} else {	foreach($user->results() as $user)		echo $user->username, '<br>';	}}

and the db file which i believe may effect it is 

<?phpclass DB {	private static $_instance = null;	private $_pdo,			$_query,			$_error = false,			$_results,			$_count = 0;			private function __construct(){				try{					$this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));				} catch(PDOException $e) {					die($e->getMessage());				}			}			public static function getInstance() {				if(!isset(self:_instance)){					self:_instance =new DB();				}				return self:_instance;		}		public function query($sql, $params = array()) {			$this->_error = false;			if($this->_query = $this->_pdo->prepare($sql)) {				$x = 1;				if(count($params)) {					foreach($params as $param) {						$this->_query->bindValue($x, $param);						$x++;					}				}				if ($this->_query->execute()){					$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);					$this->_count = $this->_query->rowCount();				} else {					$this->_error = true;				}		}		return $this;		}		public function action($action, $table, $where = array()){			if(count($where) === 3){				$operators = array('=', '>', '<', '>=', '<='); 			$field     = $where[0];			$operator  = $where[1];			$value     = $where[2];			if(in_array($operator, $operators)){				$sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";				if (!$this->query($sql, array($value))->error( )){					return $this;					}				}			}			return false;		}		public function get($table, $where){			return $this->action('SELECT *', $table, $where);		}			public function delete($table, $where) {			return $this->action('DELETE', $tabke, $where);		}		public function results() {			return $this->_results;		}	public function error() {		return $this->_error;	}	public function count(){		return $this->_count;	}}

please help i have been stuck on this all day!

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/280508-php-help/
Share on other sites

Link to post
Share on other sites

the issue will lie within your foreach loop in index, it tells you exactly what line the error occured on and what file it occurred in. also, just noticing but there is no ?> at the END of the php file. is this just not selected in the code or is it really not there?

Link to comment
https://linustechtips.com/topic/280508-php-help/#findComment-3810231
Share on other sites

Link to post
Share on other sites

the issue will lie within your foreach loop in index, it tells you exactly what line the error occured on and what file it occurred in. also, just noticing but there is no ?> at the END of the php file. is this just not selected in the code or is it really not there?

not there totally new to php 

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/280508-php-help/#findComment-3810545
Share on other sites

Link to post
Share on other sites

Buy a chance are you using a tutorial form php acadamy? this looks familiar. 

yup bang on mate :P you havent completed this class aswell have you? i have given up completely i may restart tomorrow but im actually looking for the source code.

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/280508-php-help/#findComment-3811195
Share on other sites

Link to post
Share on other sites

I haven't but i was going to pick it up again today. and i saw your post with the file website and would love to help.

 

yup bang on mate :P you havent completed this class aswell have you? i have given up completely i may restart tomorrow but im actually looking for the source code.

Move along. Nothing to see here

Link to comment
https://linustechtips.com/topic/280508-php-help/#findComment-3811589
Share on other sites

Link to post
Share on other sites

I haven't but i was going to pick it up again today. and i saw your post with the file website and would love to help.

cool awesome ill PM you!!

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/280508-php-help/#findComment-3811665
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×