-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
69 lines (45 loc) · 1.42 KB
/
signup.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
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$database = "demo";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = $_POST["name"];
$email = $_POST["email"];
$age = $_POST["age"];
$pass = $_POST["pass"];
$gender = $_POST["gender"];
$phone = $_POST["phone"];
$dob = $_POST["dob"];
$password = base64_encode($pass);
$sql = $conn->prepare("SELECT id from User WHERE email = ?");
$sql->bind_param("s", $email);
$sql->execute();
$result = $sql->get_result();
$count = $result->num_rows;
if ($count == 1) {
echo "1";
} else {
// prepare and bind
$sql = $conn->prepare("INSERT INTO User (name , email , password , phone , gender , dob , age) VALUES (?, ?, ?, ?, ?, ?, ?)");
$sql->bind_param("sssssss", $name, $email, $password, $phone, $gender, $dob, $age);
$sql->execute();
$myFile = "/xampp/htdocs/guvi/data.json";
$arr_data = array(); // create empty array
$result = $conn->query("SELECT * FROM User");
//Initialize array variable
$dbdata = array();
//Fetch into associative array
while ($row = $result->fetch_assoc()) {
$dbdata[] = $row;
}
$jsondata = json_encode($dbdata, JSON_PRETTY_PRINT);
//echo $jsondata;
file_put_contents($myFile, $jsondata);
$sql->close();
}