-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
41 lines (38 loc) · 1.28 KB
/
index.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
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Method: *");
header("Access-Control-Allow-Headers: *");
// header("content-type: Application/Json");
if($_SERVER["REQUEST_METHOD"] == "POST"){
$request = file_get_contents("php://input");
$data = json_decode($request);
$firstname = $data->firstname;
$lastname = $data->lastname;
// $username = $data->username;
$password = $data->password;
$role_id = $data->role_id;
require("config.php");
// if(!$username && !$password){
// // echo "invalid data";
// }
// $sql = "SELECT * FROM `admins` WHERE `id` = 1";
// $result = mysqli_query($_conn, $sql);
// if($result){
// $feedback = mysqli_fetch_assoc($result);
// echo print_r($feedback);
// }
// registered
$sql = "INSERT INTO `admins`(`fname`, `lastname`, `password`, `role_id`, `created_at`, `registered`) VALUE ('$firstname', '$lastname', SHA('$password'), $role_id, now(), now())";
$result = mysqli_query($_conn, $sql);
if($result){
$id = mysqli_insert_id($_conn);
echo json_encode([
"message" => "user registered successfully",
"type" => "success",
"insert_id" => $id
]);
}else{
echo "unable to insert";
// echo mysqli_error($_conn);
}
}