-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexer5.php
49 lines (39 loc) · 1.27 KB
/
exer5.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
session_start();
$employees = array(
array("name" => "John", "age" => 30, "city" => "New York"),
array("name" => "Jane", "age" => 35, "city" => "Chicago"),
array("name" => "Peter", "age" => 40, "city" => "Los Angeles")
);
$_SESSION['employees'] = $employees;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$ename = $_POST["ename"];
$found = false;
foreach ($_SESSION['employees'] as $employee) {
if ($employee["name"] == $ename) {
echo "Name: " . $employee["name"] . "<br>";
echo "Age: " . $employee["age"] . "<br>";
echo "City: " . $employee["city"] . "<br>";
$found = true;
break;
}
}
if (!$found) {
echo "No employee found with the given name.";
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Name: <input type="text" name="ename">
<input type="submit">
</form>
</body>
</html>