-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup-api.php
64 lines (61 loc) · 2.9 KB
/
signup-api.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
function json_formatter($status, $msg){
header('Content-Type: application/json');
echo json_encode(['status' => $status, 'msg' => $msg]);
}
$host = "localhost";
$user = "root";
$pass = "";
$db = "auth";
$con = mysqli_connect($host, $user, $pass, $db);
$fname = mysqli_real_escape_string($con, $_POST['fname']);
$lname = mysqli_real_escape_string($con, $_POST['lname']);
$dob = mysqli_real_escape_string($con, $_POST['dob']);
$gender = mysqli_real_escape_string($con, $_POST['gender']);
$mobile = mysqli_real_escape_string($con, $_POST['mobile']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$pwd = mysqli_real_escape_string($con, $_POST['pwd']);
$cpwd = mysqli_real_escape_string($con, $_POST['cpwd']);
if (empty($fname) || empty($lname) || empty($gender) || empty($mobile) || empty($email) || empty($pwd) || empty($cpwd)) {
json_formatter(false, "All fields are required");
}else{
$current = time();
if(strtotime($dob) > $current){
json_formatter(false, "Invalid Date of Birth");
}else{
$genders = ['m', 'f'];
if (!in_array($gender, $genders)) {
json_formatter(false, "Invalid Gender");
}else{
if (!filter_var($email, FILTER_DEFAULT)) {
json_formatter(false, "Invalid Email");
}else{
$check = "SELECT * FROM users WHERE mobile='$mobile'";
$check = mysqli_query($con, $check);
if(mysqli_num_rows($check) > 0){
json_formatter(false, "Mobile number have been used");
}else{
$check = "SELECT * FROM users WHERE email='$email'";
$check = mysqli_query($con, $check);
if(mysqli_num_rows($check) > 0){
json_formatter(false, "Email have been used");
}else{
if($pwd != $cpwd){
json_formatter(false, "Invalid Confirm Password");
}else{
$pwd_hash = password_hash($pwd, PASSWORD_DEFAULT);
$insert = "INSERT INTO users(first, last, dob, gender, mobile, email, pwd)
VALUES('$fname', '$lname', '$dob', '$gender', '$mobile', '$email', '$pwd_hash')";
if(mysqli_query($con, $insert)){
json_formatter(true, "Success");
}else{
json_formatter(true, "Error");
}
}
}
}
}
}
}
}
?>