class User extends mysqli {
public $username, $email, $password;
function __construct($hn, $un, $pw, $db, $port, $socket, $charset) {
parent::__construct($hn, $un, $pw, $db, $port, $socket);
$this->set_charset($charset);
}
function hashPasword($pass) {
return password_hash($pass, PASSWORD_DEFAULT);
}
function saveUser() {
$this->query("INSERT INTO users VALUES (NULL, '" . $this->username . "', '" . $this->email . "', '" . $this->hashPasword($this->password) . "')");
}
function printData() {
echo "Username: " . $this->username . "<br>";
echo "Email: " . $this->email . "<br>";
echo "Password: " . $this->hashPasword($this->password) . "<br>";
}
function __destruct() {
$this->close();
}
}
require_once 'config.php';
require_once 'classes/User.php';
if (isset($_POST['username']) &&
isset($_POST['email']) &&
isset($_POST['password'])) {
$user = new User($hn, $un, $pw, $db, $port, null, $charset);
$user->username = $_POST['username'];
$user->email = $_POST['email'];
$user->password = $_POST['password'];
$user->saveUser();
}
if (isset($_POST['username']) &&
isset($_POST['email']) &&
isset($_POST['password']))
if ( $_POST['username'] && $_POST['email'] && $_POST['password'] )
if (trim($_POST['username']) && trim($_POST['email']) && trim($_POST['password']))