malina95
Мастер
Дата регистрации:
15.07.2012 07:13:44
Сообщений: 208
<?php
class User {
public $mysqli;
public $error;
public function getError($error) {
return $this->error = $error;
}
public function connectDB() {
return $this->mysqli;
}
public function registerUser ($login, $password) {
$login = trim(htmlspecialchars($login));
$password = trim(htmlspecialchars($password));
if (empty($login) AND strlen($login) > 3) {
unset($login);
return $this->getError('Вы не ввели Логин');
}
if (empty($password) AND strlen($password) > 6) {
unset($password);
return $this->getError('Вы не ввели Пароль');
}
if (isset($login) AND isset($password)) {
//$mysqli = new mysqli("localhost", "Admin", "udiram04", "oop"
$mysqli = $this->connectDB();
$isset_login = $mysqli->query("SELECT `login` FROM `reg` WHERE `login` = '".$login."'"
$arr_isset = $isset_login->fetch_assoc();
if (!$arr_isset['login'] == "" {
return $this->getError("Такой логин существует"
}
$mysqli->query("INSERT INTO `reg` (`login`, `password`, `date`) VALUES ('".$login."', '".$password."', UNIX_TIMESTAMP())"
$id = $mysqli->insert_id;
$result = $mysqli->query("SELECT * FROM `reg` WHERE `id` = '$id'"
$arr = $result->fetch_assoc();
return "Ваш логин: ".$arr['login']."<br />Ваш пароль: ".$arr['password']."<br />Дата регистрации: ".date("d:m:y h:s", $arr['date']);
}
}
public function deleteUser($id_user) {
$mysqli = $this->connectDB();
$delete_user = $mysqli->query("SELECT `id` FROM `reg` WHERE `id` = '$id_user'"
$arr_del_user = $delete_user->fetch_assoc();
if (empty($arr_del_user['id'])) {
return $this->getError("Такого пользователя нет"
}
else {
$del_user = $mysqli->query("DELETE FROM `reg` WHERE `id` = '$id_user' LIMIT 1"
if ($del_user === true) {
return $this->getError("Пользователь успешно удалён"
}
}
}
}
?>
<?php
require_once "register.php";
if (isset($_POST['submit'])) {
$mysqli = new mysqli("localhost", "Admin", "udiram04", "oop"
$user = new User();
$user->mysqli = $mysqli;
echo $user->registerUser($_POST['login'], $_POST['password']);
}
echo <<<TXT
<form action = "" method = "post">
<input type = "text" name = "login" />
<input type = "password" name = "password" />
<input type = "submit" name = "submit" />
</form>
TXT;
?>