CREATE TABLE IF NOT EXISTS `usuarios` (
`id_user` int(5) unsigned NOT NULL AUTO_INCREMENT,
`nombre` varchar(30) NOT NULL,
`usernombre` varchar(30) NOT NULL,
`password` char(40) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`id_user`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
INSERT INTO `usuarios` (`id_user`, `nombre`, `usernombre`, `password`, `email`) VALUES
(1, 'fernando ojeda', 'fernarey1810', 'c5f617e3dfc03337ef4eea22cad65b56d25c45f5', '[email protected]');
index.php
Código PHP:
Ver original
<?php include 'db.php'; include 'user.php'; $user = User::getByUsername('fernarey1810'); if ($user->userId) { echo 'Lo sentimos, esa cuenta ya existe. Prueba un nombre de usuario diferente.'; } ?>
db.php
Código PHP:
Ver original
<?php if(!$connection) { } if(!$db_select) { } ?>
user.php
Código PHP:
Ver original
<?php class User { private $uid; private $fields; public function __construct() { $this->uid = null; 'username' => '', 'password' => '', 'emailAddr' => ''); } public function __get($field) { if ($field == 'userId') { return $this->uid; }else { return $this->fields[$field]; } } public function __set($field, $value) { $this->fields[$field] = $value; } } public static function getByUsername($username) { $u = new User(); // ESTA CONSULTA NO FUNCIONA NOSE PORQUE $query = "SELECT id_user, nombre, password, email FROM usuarios WHERE usernombre = '$username'"; $u->nombre = $row['nombre']; $u->username = $username; $u->password = $row['password']; $u->emailAddr = $row['email']; $u->uid = $row['id_user']; } return $u; } }