-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadduser.php
64 lines (44 loc) · 1.48 KB
/
adduser.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
<?php
session_start();
//Open a new connection to the MySQL server
$mysqli = new mysqli('localhost', 'root', '', 'perfectcup');
//Output any connection error
if ($mysqli->connect_error) {
die('Error : (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}
$fname = mysqli_real_escape_string($mysqli, $_POST['fname']);
$lname = mysqli_real_escape_string($mysqli, $_POST['lname']);
$email = mysqli_real_escape_string($mysqli, $_POST['email']);
$password = mysqli_real_escape_string($mysqli, $_POST['password']);
//VALIDATION
if (strlen($fname) < 2) {
echo 'fname';
} elseif (strlen($lname) < 2) {
echo 'lname';
} elseif (strlen($email) <= 4) {
echo 'eshort';
} elseif (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
echo 'eformat';
} elseif (strlen($password) <= 4) {
echo 'pshort';
//VALIDATION
} else {
//PASSWORD ENCRYPT
$spassword = password_hash($password, PASSWORD_BCRYPT, array('cost' => 12));
$query = "SELECT * FROM members WHERE email='$email'";
$result = mysqli_query($mysqli, $query) or die(mysqli_error());
$num_row = mysqli_num_rows($result);
$row = mysqli_fetch_array($result);
if ($num_row < 1) {
$insert_row = $mysqli->query("INSERT INTO members (fname, lname, email, password) VALUES ('$fname', '$lname', '$email', '$spassword')");
if ($insert_row) {
$_SESSION['login'] = $mysqli->insert_id;
$_SESSION['fname'] = $fname;
$_SESSION['lname'] = $lname;
echo 'true';
}
} else {
echo 'false';
}
}
?>