-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
40 lines (34 loc) · 1.27 KB
/
register.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
<?php
include 'common.php';
try{
$msg = '';
if(isset($_POST["username"]) && isset($_POST["pass"]) && isset($_POST["user-mail"])) {
$username = mysql_real_escape_string(addslashes(trim($_POST['username'])));
$email = mysql_real_escape_string($_POST["user-mail"]);
$password = mysql_real_escape_string(md5($_POST['pass']));
$date_reg = time();
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$msg = "Invalid email format";
throw new Exception();
}
$sql=mysql_query("SELECT * FROM users WHERE login='$username'");
if(mysql_num_rows($sql)>0){
$msg = "Name already exists";
throw new Exception();
}
$sql = mysql_query("SELECT * FROM users WHERE email='$email'");
if(mysql_num_rows($sql)>0){
$msg = "E-mail already exists";
throw new Exception();
}
$query = "INSERT INTO users (login, pass, email, date_reg) VALUES ('$username', '$password', '$email', '$date_reg')";
$result = run_q($query);
if($result){
$msg = "User Created Successfully.";
throw new Exception();
}
}
} catch (Exception $e){
$_SESSION['msg'] = $msg;
header('Location: index.php');
}