-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
46 lines (39 loc) · 1.61 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
41
42
43
44
45
46
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Access-Control-Allow-Methods: *");
include 'DbConnect.php';
$objDb = new DbConnect;
$conn = $objDb->connect();
$method=$_SERVER['REQUEST_METHOD'];
switch($method){
case "GET":
$sql = "SELECT * FROM signup";
$stmt = $conn->prepare($sql);
$stmt -> execute();
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($users);
break;
case "POST":
$user=json_decode(file_get_contents('php://input'));
$sql = "INSERT INTO signup(f_name,l_name,u_name,dob,gender,email,pass1,mobile,role1) VALUES(:firstname,:lastname,:username,:occupantdob,:gender,:email,:pass2,:occupant_mobile,:Role1)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':firstname',$user->firstname);
$stmt->bindParam(':lastname',$user->lastname);
$stmt->bindParam(':username',$user->username);
$stmt->bindParam(':occupantdob',$user->occupantdob);
$stmt->bindParam(':gender',$user->gender);
$stmt->bindParam(':email',$user->email);
$stmt->bindParam(':pass2',$user->pass2);
$stmt->bindParam(':occupant_mobile',$user->occupant_mobile);
$stmt->bindParam(':Role1',$user->Role1);
if($stmt->execute()) {
$response = ['status' => 1, 'message' => 'Record created successfully.'];
} else {
$response = ['status' => 0, 'message' => 'Failed to create record.'];
}
echo json_encode($response);
break;
}