Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2.  
  3. require '/libs/db.php';
  4.  
  5. $data = $_POST;
  6. if (isset($data['reg'])) {
  7.     # массив данных username, email, password, password_2
  8.     $errors = array();
  9.     if (trim($data['username']) == '') {
  10.         # проверяем пустое ли поле username
  11.         $errors[] = 'enter your account name';
  12.     }
  13.  
  14.     if (trim($data['email']) == '') {
  15.         # проверяем пустое ли поле email
  16.         $errors[] = 'enter your email';
  17.     }
  18.  
  19.     if ($data['password'] == '') {
  20.         # проверка поля password
  21.         $errors[] = 'enter your password';
  22.     }
  23.  
  24.     if ($data['confim_password'] != $data['password']) {
  25.         # совпадают ли  password == password_2
  26.         $errors[] = 'password2 incorrect';
  27.     }  
  28.  
  29.     if ( R::count('accounts', "login = ?", array($data['username'] )) > 0) {
  30.         $errors[] = 'username exist';
  31.     }
  32.  
  33.     if ( empty($errors)) { // если нет ошибок записываем данные в mysql
  34.         $user = R::dispense('accounts');
  35.         $user -> login = $data['username'];
  36.         $user -> email = $data['email'];
  37.         $user -> password = base64_encode(pack('H*', sha1($data['password'])));
  38.         R::store($user);
  39.  
  40.         echo '<div style="color: green;">done</div>';
  41.  
  42.     }   else
  43.    
  44.     {
  45.         echo '<div style="color: red;">'.array_shift($errors).'</div>';
  46.     }
  47. }
  48.  
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement