-
Notifications
You must be signed in to change notification settings - Fork 4
/
profile.php
55 lines (39 loc) · 1.19 KB
/
profile.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
<?php
require 'vendor/autoload.php'; // Include the MongoDB PHP Library
// Create a MongoDB client
$client = new MongoDB\Client('mongodb://localhost:27017');
// Select a database and collection
$db = $client->mydb;
$collection = $db->data;
// Get the form data
$Username= $_POST['Username'];
$age = $_POST['age'];
$dob = $_POST['dob'];
$contact = $_POST['contact'];
$address = $_POST['address'];
$about = $_POST['about'];
// Insert the form data into MongoDB
$document = [
'Username' => $Username,
'age' => $age,
'dob' => $dob,
'contact' => $contact,
'address' => $address,
'about' => $about,
];
//if filed is empty send message in json to ajax
if(empty($_POST['Username']) || empty($_POST['age']) || empty($_POST['dob']) || empty($_POST['contact']) || empty($_POST['address']) || empty($_POST['about'])){
echo json_encode( array('message' => 'fill all the fields') );
exit();
}
$result = $collection->insertOne($document);
//send data.success is true in json to ajax
if($result){
echo json_encode( array('success' => true) );
}
else{
echo json_encode( array('message' => 'error') );
exit();
}
exit();
?>