-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete_addr.php
37 lines (22 loc) · 1.11 KB
/
delete_addr.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
<?php
session_start();
require "vendor/autoload.php";
$user_id = $_SESSION["logged"]["_id"];
$place_id = $_POST["place_id"];
try {
$m = new MongoDB\Client("mongodb://vinay0410:[email protected]:23725/pizza");
$db = $m->pizza;
$collection = $db->users;
$collection->updateOne([ '_id' => new MongoDB\BSON\ObjectID($user_id)], [ '$pull' => [ 'address' => [ 'place_id' => $place_id ] ] ]);
$result = $collection->findOne(['_id' => new MongoDB\BSON\ObjectID($user_id)], ['typeMap' => ['document' => 'array', 'root' => 'array']]);
$_SESSION["logged"] = $result;
} catch (MongoDB\Driver\Exception\ConnectionTimeoutException $e) {
echo json_encode(array('error' => True, 'msg' => "Couldn't Connect to Database"));
exit();
} catch (Exception $e) {
#die("Caught Exception failed to Connect".$e->getMessage()."\n");
echo json_encode(array('error' => True, 'msg' => $e->getMessage()));
exit();
}
?>
<div id="success" class="alert alert-success" role="alert"><?php echo "Item Deleted Successfully"; ?></div>