-
Notifications
You must be signed in to change notification settings - Fork 0
/
reg_js.php~
67 lines (66 loc) · 1.94 KB
/
reg_js.php~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
session_start();
$login = $_POST['login'];
$password = $_POST['password'];
$email = $_POST['email'];
$re_password = $_POST['re_password'];
$error_reg = array();
$error = 2;
include("connect_db.php");
if (empty($login)){
array_push($error_reg,'not entered login');
$error = 1;
} else{
$STH = $DBH->prepare('SELECT * from user WHERE login=:login');
$STH->bindValue(':login',$login);
$STH->execute();
while($row = $STH->fetch(PDO::FETCH_ASSOC)){
array_push($error_reg,'user with that login exist');
$error = 1;
}
}
if (empty($password)){
array_push($error_reg,'not entered password');
$error = 1;
}
if (empty($re_password)){
array_push($error_reg,'not entered RE password');
$error = 1;
}
if(!($password === $re_password)){
array_push($error_reg,'Password and RE password different');
$error = 1;
}
if(empty($email)){
array_push($error_reg,'not entered email');
$error = 1;
}elseif(!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/",$email)){
array_push($error_reg,'email is incorrect format');
$error = 1;
}else{
$STH = $DBH->prepare('SELECT * from user WHERE email=:email');
$STH->bindValue(":email", $email, PDO::FETCH_ASSOC);
$STH->execute();
$res = $STH->fetchAll();
if(!empty($res)){
array_push($error_reg,'user with that email exist');
$error = 1;
}
}
if ($error == 2 ){
$date_reg=date("l dS of F Y ");
$roles = array();
$user='user';
array_push($roles,$user);
$data = array($login,$password ,$email,$date_reg,"empty.jpg",serialize($roles));
$STH = $DBH->prepare("INSERT INTO user (login,password,email,date_reg,photo,roles) values ( ?, ?,?,?,?,?)");
$STH->execute($data);
$_SESSION['ent'] = 2;
$_SESSION['login'] = $login;
//$_SESSION['profil_id']=;
Header("Location: index.php");
}else{
$_SESSION['erreg'] = $error_reg;
Header("Location: reg.html");
}
?>