Here is the code i'm usingFatal error: Call to undefined method mysqli_stmt::get_result() in /home/aleeious/public_html/beta/libs/User.class.php on line 78
register.php
Code: Select all
<?php
// include smarty library
require('libs/Smarty.class.php');
// include database class
require_once('libs/Database.class.php');
// include user class
require_once('libs/User.class.php');
// create instance of smarty library
$smarty = new Smarty();
// if the form wasn't submited
if(!isset($_POST["submit"]))
{
// display it
$smarty->display('register.tpl');
}
// otherwise the form was submitted
else
{
// if the username is empty
if(empty($_POST["username"]))
{
// so display an error stating the username is empty
$smarty->assign('error', 'username is empty');
// and display it
$smarty->display('error.tpl');
// and terminate
exit;
}
// if the username is too short or too big
elseif(strlen($_POST["username"]) < 4 || strlen($_POST["username"]) > 16)
{
// so display an error stating the required usernamelength
$smarty->assign('error', 'username must be 4-16 characters long');
// and display it
$smarty->display('error.tpl');
// and terminate
exit;
}
// otherwise the username is filled in
else
{
// so sanitize it
$username = $_POST["username"];
}
// if the password is empty
if(empty($_POST["password"]))
{
// so display an error stating the password is empty
$smarty->assign('error', 'password is empty');
// and display it
$smarty->display('error.tpl');
// and terminate
exit;
}
// if the password is too short or too big
elseif(strlen($_POST["password"]) < 4 || strlen($_POST["password"]) > 16)
{
// so display an error stating the required password length
$smarty->assign('error', 'password must be 4-16 characters long');
// and display it
$smarty->display('error.tpl');
// and terminate
exit;
}
// otherwise the password is ok
else
{
// so sanitize it
$password = $_POST["password"];
}
// if the password verification is empty
if(empty($_POST["verifypassword"]))
{
// so display an error stating the password verification is empty
$smarty->assign('error', 'you must verify your password');
// and display it
$smarty->display('error.tpl');
// and terminate
exit;
}
// if the password and password verification don't match
elseif($_POST["password"] != $_POST["verifypassword"])
{
// so display an error stating the passwords don't match
$smarty->assign('error', 'both password and verify password must match');
// and display it
$smarty->display('error.tpl');
// and terminate
exit;
}
// otherwise the password verification is ok
else
{
// so sanitize it
$verifypassword = $_POST["verifypassword"];
}
// if the email is empty
if(empty($_POST["email"]))
{
// so display an error stating the email is empty
$smarty->assign('error', 'email is empty');
// and display it
$smarty->display('error.tpl');
// and terminate
exit;
}
// if the email is invalid
//elseif(strlen($_POST["email"]) < 4 || strlen($_POST["password"]) > 16)
//{
// so display an error stating the email is invalid
//$smarty->assign('error', 'the mail address you entered is invalid');
// and display it
//$smarty->display('error.tpl');
// and terminate
//exit;
//}
// otherwise the email is ok
else
{
// so sanitize it
$email = $_POST["email"];
}
// open a connection to the database
$db = new Database();
// create an instance of the user class
$user = new User($db);
// check to see if the username already excists
if($user->exists($username))
{
// if the username already excists display an error stating it
$smarty->assign('error', 'that username already exists');
// display it
$smarty->display('error.tpl');
}
// if everything checks out display an error stating registrations are currently closed
$smarty->assign('error', 'registrations are currently disabled');
// display it
$smarty->display('error.tpl');
}
?>
Code: Select all
<?php
// import configuration data
require_once('./config.php');
class Database extends mysqli
{
// instance of class
private $instance;
// class constructor
public function __construct()
{
// turn on error reporting
mysqli_report(MYSQLI_REPORT_ALL);
parent::__construct(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);
// if the connection couldn't be established
if(mysqli_connect_errno())
{
// throw an exception
throw new exception(mysqli_connect_error(), mysqli_connect_errno());
}
}
// returns instance of class
public static function getInstance() {
// if an instance doesn't excist
if(!$this->instance)
{
// create a new instance
$this->instance = new self();
}
// otherwise return the class instance
return $this->instance;
}
}
?>
Code: Select all
<?php
class User
{
// database instanceof
protected $db;
// username
private $username;
// user's password
private $password;
// user's email
private $email;
/**
* class constructor
*/
public function __construct(Database $db)
{
// get instance of database
$this->db = $db;
}
/**
* retruns username
*/
public function getUsername()
{
return $this->password;
}
/**
* retruns password
*/
public function getPassword()
{
return $this->password;
}
/**
* retruns email
*/
public function getEmail()
{
return $this->email;
}
/**
* adds the user to the database
* @param username of user to add
* @param password of user to add
* @param email address of user to add
*/
public function add($username, $password, $email)
{
}
/**
* checks if the user already excists in the database
* @param username of user to check
* @returns true if username excists, otherwise false
*/
public function exists($username)
{
// prepare the sql statement
$statement = $this->db->prepare('SELECT id FROM ' . TABLE_USERS . ' WHERE USERNAME = ?');
// bing the variables
$statement->bind_param('i', $id);
// if the statement executed successfully
if ($statement->execute())
{
// get the number of results
$result = $statement->get_result();
// if a result exists
if($result)
{
// return true
return true;
}
// otherwise return false
return false;
}
}
/**
* gets user info and populates it
* @param username of user to retrieve info of
*/
public function getInfo($username)
{
}
}
?>
Code: Select all
$result = $statement->get_result();
Sincerely,
Aleeious