User not adding to the db after registering

chiefqueef

gooby pls
Jan 8, 2012
404
104
Trying to use the habbopixel cms that was posted on here a while back and upon registering the users dont get added into the db.

Trying to use it with the db provided in @JMG s hxbbo release

im sure this is because the php doesnt match the tables in the db but im not sure what to change to make it work

class.php

Code:
<?php
// CLASS (NE PAS MODIFIER)
// DB_NAME = HOTE DE VOTRE BASE DE DONNEES
// DB_USER = NOM DE VOTRE BASE DE DONNEES
// DB_MDP = MOT DE PASSE DE VOTRE BASE DE DONNEES
// DB_HOST = HÔTE DE VOTRE BASE DE DONNEES
class Database {

    private $db_name;
    private $db_user;
    private $db_mdp;
    private $db_host;
    private $pdo;

    public function __construct($db_name = 'habbo', $db_user = 'root', $db_mdp = 'hotel', $db_host = 'localhost') {
        $this->db_name = $db_name;
        $this->db_user = $db_user;
        $this->db_mdp = $db_mdp;
        $this->db_host = $db_host;
    }

    private function getpdo() {
        if($this->pdo == null) {
            $pdo = new PDO('mysql:host='.$this->db_host.';dbname='.$this->db_name, $this->db_user, $this->db_mdp);
            $pdo->exec('SET NAMES utf8');
            $this->pdo = $pdo;
        }

        return $this->pdo;
    }

    public function query($requete, $args = array(null)) {
        if(!empty($args)) {
            $req = $this->getpdo()->prepare($requete);
            $req->execute($args);
        } else {
            $req = $this->getpdo()->query($requete);
        }
        return $req;
    }

    public function lastInsertId() {
        return $this->pdo->lastInsertId();
    }
}

Class Core {
    public function F_HTML($var) {
        $var = htmlspecialchars(trim($var));
        return $var;
    }

    public function F_HTMLBBCode($var) {
        $var = htmlspecialchars(trim($var));
        $var = utf8_encode($var);
        $var = str_replace('', '', $var);
        $var = utf8_decode($var);
        return $var;
    }

    public function C_PASS($var) {
        $var = password_hash($var, PASSWORD_BCRYPT);
        return $var;
    }
   
    public function Redirect($var) {
        if(headers_sent()) {
            echo '<script language="JavaScript">document.location.href="'.$var.'"</script>';
            exit();
        } else {
            header('Location:'.$var);
            exit();
        }
    }
}

$core = new Core();

Class Account {
    public function UserisBanned($pseudo) {
        global $pdo;
        $bdd = $pdo->query('SELECT * FROM bans WHERE value = ?', [$pseudo]);
        if($bdd->rowCount() > 0) {
            die('Une erreur est survenue, votre compte a été banni !');
        }
    }

     public function IPisBanned($ip) {
        global $pdo;
        $bdd = $pdo->query('SELECT * FROM bans WHERE value = ?', [$ip]);
        if($bdd->rowCount() > 0) {
            die('Une erreur est survenue, votre compte a été banni !');
        }
    }

    public function isConnected() {
        if(isset($_SESSION['id'])) {
            if(headers_sent()) {
                echo '<script language="JavaScript">document.location.href="'.@URL.'/home"</script>';
                exit();
            } else {
                header('Location:'.@URL.'/home');
                exit();
            }
        }
    }

    public function isNotConnected() {
        if(!isset($_SESSION['id'])) {
            if(headers_sent()) {
                echo '<script language="JavaScript">document.location.href="'.@URL.'/index"</script>';
                exit();
            } else {
                header('Location:'.@URL.'/index');
                exit();
            }
        }
    }

    public function isGrade($nombre, $id) {
        global $pdo;
        $bdd = $pdo->query('SELECT * FROM users WHERE id = ?', [$id]);
        $req = $bdd->fetch();
        if($req['rank'] >= $nombre) {
            return true;
        }
        header('Location:'.@URL.'/home');
        exit();
    }

    public function GetYourInfos($id, $infos) {
        global $pdo;
        $bdd = $pdo->query('SELECT * FROM users WHERE id = ?', [$id]);
        while($req = $bdd->fetch()) {
            return $req[$infos];
        }
        return false;
    }

    public function Update($id) {
        global $pdo;
        $bdd = $pdo->query('UPDATE users SET last_online = ?, ip_last = ? WHERE id = ?', [time(), $_SERVER['REMOTE_ADDR'], $id]);
    }
}

$account = new Account();
?>

/app/signup.php

Code:
<?php
require '../global.php';
$pdo = New Database();
$account->IPisBanned($_SERVER['REMOTE_ADDR']);
$account->isConnected();

if(!empty($_POST['username']) AND !empty($_POST['email']) AND !empty($_POST['password']) AND !empty($_POST['password_confirmation'])) {
    $bdd = $pdo->query('SELECT id FROM users WHERE username = ?', [$core->F_HTML($_POST['username'])]);
    if($bdd->rowCount() == 0) {
          if(preg_match('`^([a-zA-Z0-9-=?!@]{3,15})$`', $core->F_HTML($_POST['username']))) {
            $bdd2 = $pdo->query('SELECT id FROM users WHERE email = ?', [$core->F_HTML($_POST['email'])]);
            if($bdd2->rowCount() == 0) {
                if(filter_var($core->F_HTML($_POST['email']), FILTER_VALIDATE_EMAIL)) {
                      if($_POST['password'] == $_POST['password_confirmation']) {
                        if(strlen($_POST['password']) >= 6 AND strlen($_POST['password_confirmation']) >= 6) {
                            $bdd3 = $pdo->query('INSERT INTO users (username, password, mail, credits, vip_points, activity_points, look, motto, account_created, ip_reg) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [$core->F_HTML($_POST['username']), $core->C_PASS($_POST['password']), $core->F_HTML($_POST['email']), "0", "0", "0", "ch-235-92.sh-295-92.hr-3163-61.hd-180-1.lg-275-92", "Nouveau !", time(), $_SERVER['REMOTE_ADDR']]);
                            $_SESSION['id'] = $pdo->lastInsertId();
                            echo 'success';
                        } else {
                            echo 'Les mots de passe ne correspondent pas.';
                        }
                    } else {
                        echo 'Ton mot de passe doit contenir plus de 6 caractères.';
                    }
                } else {
                    echo 'Ton adresse e-mail n\'est pas valide.';
                }
            } else {
                echo 'Cette adresse e-mail est déjà utilisée.';
            }
        } else {
            echo 'Ton pseudo n\'est pas valide.';
        }
    } else {
        echo 'Ce pseudo est déjà utilisé.';
    }
} else {
    echo 'Merci de remplir tous les champs.';
}
?>
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Look at what you're inserting into the database, and look at the table provided. Any columns that do not appear in the insert query, check if they have a default value in the database.
 

Users who are viewing this thread

Top