-
Notifications
You must be signed in to change notification settings - Fork 2
/
register.php
83 lines (66 loc) · 2.49 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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
if(isset($_POST['fname']) &&
isset($_POST['uname']) &&
isset($_POST['pass'])){
include "db_conn.php";
$fname = $_POST['fname'];
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$data = "fname=".$fname."&uname=".$uname;
if (empty($fname)) {
$em = "Full name is required";
header("Location: register.html?error=$em&$data");
exit;
}else if(empty($uname)){
$em = "User name is required";
header("Location: register.html?error=$em&$data");
exit;
}else if(empty($pass)){
$em = "Password is required";
header("Location: register.html?error=$em&$data");
exit;
}else {
// hashing the password
$pass = password_hash($pass, PASSWORD_DEFAULT);
if (isset($_FILES['pp']['name']) AND !empty($_FILES['pp']['name'])) {
$img_name = $_FILES['pp']['name'];
$tmp_name = $_FILES['pp']['tmp_name'];
$error = $_FILES['pp']['error'];
if($error === 0){
$img_ex = pathinfo($img_name, PATHINFO_EXTENSION);
$img_ex_to_lc = strtolower($img_ex);
$allowed_exs = array('jpg', 'jpeg', 'png');
if(in_array($img_ex_to_lc, $allowed_exs)){
$new_img_name = uniqid($uname, true).'.'.$img_ex_to_lc;
$img_upload_path = '../assets/upload/'.$new_img_name;
move_uploaded_file($tmp_name, $img_upload_path);
// Insert into Database
$sql = "INSERT INTO users(fname, username, password, pp)
VALUES(?,?,?,?)";
$stmt = $conn->prepare($sql);
$stmt->execute([$fname, $uname, $pass, $new_img_name]);
header("Location: login.html?success=Your account has been created successfully");
exit;
}else {
$em = "You can't upload files of this type";
header("Location: login.html?error=$em&$data");
exit;
}
}else {
$em = "unknown error occurred!";
header("Location: register.html?error=$em&$data");
exit;
}
}else {
$sql = "INSERT INTO users(fname, username, password)
VALUES(?,?,?)";
$stmt = $conn->prepare($sql);
$stmt->execute([$fname, $uname, $pass]);
header("Location: login.html?success=Your account has been created successfully");
exit;
}
}
}else {
header("Location: login.html?error=error");
exit;
}