-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
54 lines (48 loc) · 1.63 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
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.echo
*/
include_once 'db_connect.php';
// opening db connection
$db = new db_connect();
$connetion = $db->connect();
$errors = array();
$data = array();
// put all the value from the input value, here we can see the value of key['myEmail']
$_POST = json_decode(file_get_contents('php://input'), true);
// checking for blank values.
if (empty($_POST['myPassword'])) {
$errors['myPassword'] = 'Password is required.';
}
if (empty($_POST['myEmail'])) {
$errors['myEmail'] = 'Email is required.';
}
if (empty($_POST['rolecode'])) {
$errors['rolecode'] = 'Role is required.';
}
if (!empty($errors)) {
// put the errors array in data array
$data['errors'] = $errors;
} else {
$data['message'] = 'Form data is going well';
// response back. and put the value out of json_decoded array
$userEmail = $_POST['myEmail'];
$pass = $_POST['myPassword'];
$rolecode = $_POST['rolecode'];
global $connetion;
$result = mysqli_query($connetion, "INSERT INTO `members` ( `name`, `email`,
`phone`, `aboutme`, `password`,`rolecode`) VALUES
( 'yuhuang', '$userEmail', '12345678','aboutme: I am yuhu, from PCA , Oslo','$pass','$rolecode');");
if (!$result) {
die('failed to connect [' . $connetion->connect_error . ']');
} else {
session_start();
$_SESSION['user'] = $userEmail;
echoResponse(200, $session);
}
}
// put this in json fomat again
echo json_encode($data);
?>