-
Notifications
You must be signed in to change notification settings - Fork 0
/
emp_update.php
33 lines (30 loc) · 1.08 KB
/
emp_update.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
<?php
require 'vendor/autoload.php';
/*To update a document from the collection*/
$mclient = new MongoDB\Client;
$msdb = $mclient->company;
$empcollection = $msdb->emp;
$id = file_get_contents("file.txt");
$valid = $empcollection->findOne(
['_id' => $id]
);
if($valid)
{
$designation = $_POST['designation'];
$salary = $_POST['salary'];
$address = $_POST['address'];
if($salary!="")
$update_result1 = $empcollection->updateOne(['_id' => $id],['$set' =>['salary' =>$salary]]);
if($designation!="")
$update_result2 = $empcollection->updateOne(['_id' => $id],['$set' =>['designation' =>$designation]]);
if($address!="")
$update_result3 = $empcollection->updateOne(['_id' => $id],['$set' =>['address' =>$address]]);
echo '<script type="text/javascript">';
echo 'alert("Updated Successfully!");';
echo 'window.location.href = "emp_query.php";';
echo '</script>';
}
else echo "<script type='text/javascript'> alert('Invalid ID');";
echo 'window.location.href = "index.php";';
echo " </script>";
?>