-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_all_patients.php
90 lines (84 loc) · 2.09 KB
/
view_all_patients.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php //views all he database contents
// database access parameters
// alter this as per your configuration
session_start();
if(isset($_SESSION['Username'])){
$host = "localhost";
$user = "postgres";
$pass = "cmsc128";
$db = "UHS_Information_Management_System";
// open a connection to the database server
$connection = pg_connect("host=localhost port=5432 dbname=UHS_Information_Management_System user=postgres password=cmsc128");
if (!$connection)
{
die("Could not open connection to database server");
}
// generate and execute a query
$query = "SELECT * FROM patient ORDER BY username";
$result = pg_query($connection, $query) or die("Error in query: $query." . pg_last_error($connection));
$rows = pg_num_rows($result); // get the number of rows in the resultset
// echo "There are currently $rows records in the database.";
// if records present
if ($rows > 0){
// iterate through resultset
?>
<html>
<head>
</head>
<body>
<script>
function delete_me(){
var r=confirm("Are you sure you want to delete this account?");
if (r==true)
{
x="You pressed OK!";
}
else
{
x="You pressed Cancel!";
}
}
</script>
<center><table id="data" cellpadding=5cellspacing=0>
<h1>List of Patients</h1>
<tr>
<th>Username</th>
<th>Name</th>
<th>Medical history</th>
<th>Gender</th>
<th>Age</th>
</tr>
<?php
for ($i=0; $i<$rows; $i++){
$row = pg_fetch_object($result, $i);
?>
<tr>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->medical_history;?></td>
<td><?php echo $row->gender;?></td>
<td><?php echo $row->age;?></td>
<td><a href="edit_patient.php?username=<?php echo $row->username;?>&submit=Submit" >Edit</a></td>
<td><a href="delete_patient.php?username=<?php echo $row->username;?>&submit=Submit" onclick='delete_me();'>Delete</a></td>
</tr>
<?php
}
?></table></center>
<?php
}
// if no records present
// display message
else{
?>
<font size="-1">No data available.</font>
<?php
}
// close database connection
pg_close($connection);
echo "<a href='logout.php'>Logout</a>";
}
else{
echo "Not logged in!";
}
?>
</html>