-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectViewPet.php
More file actions
235 lines (202 loc) · 9.28 KB
/
ProjectViewPet.php
File metadata and controls
235 lines (202 loc) · 9.28 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
///////////////////////////////////////////////////////
// Name: Nancy Mikyska
// Login: nancy
// Class: CIS-2360 Fall 2017
// Assignment: project create new adoption
// File: ProjectViewPet.php
// Purpose: Display all details of single pet
///////////////////////////////////////////////////////
-->
<?php
///////////////////////////////////////
//pet query:
// STEP #1: Create PHP Variables for each variable that you need
// to bind to your SQL statements. Skip this step if your SQL
// SQL statement does not have bind variables (question marks).
$petId = filter_input(INPUT_GET, "pet");
// STEP #2: Connect to the database. Do this only once, even if
// you have multiple queries on your page.
require_once("MySqlConnectStudentDb.php");
// STEP #3: Create your SQL statement as a string. Use bind
// variables (question marks) for any user input. Do not use
// user content directly in your SQL statement.
$queryPet = "SELECT *
FROM PetsView
WHERE PetId = ?";
//return just one pet don't need the order by
// STEP #4: Create and prepare the statement. The statement
// is the binary version of the statement
$stmtPet = mysqli_stmt_init($dbc);
if(!mysqli_stmt_prepare($stmtPet, $queryPet))
die("Failed to prepare statement\n");
// STEP #5: Bind the PHP variables from step #1 to the statement.
// Each question mark in the $query must be bound to the
// statement ($stmt). Only bind true variables (e.g. no function
// calls). Use "s" for strings, "d" for float (a.k.a. double),
// and "i" for integers. Skip this step if there are no bind variables
// in your SQL statement.
mysqli_stmt_bind_param($stmtPet, "i", $petId);
// STEP #6: Execute statement and show any errors.
mysqli_stmt_execute($stmtPet);
if(mysqli_errno($dbc) !== 0)
{
echo("Error number: " . mysqli_errno($dbc));
echo("Error description: " . mysqli_error($dbc));
die();
}
// STEP #7: Get results. Use only for SELECT statements. Skip for
// INSERT, UPDATE, DELETE, etc.
$resultPet = mysqli_stmt_get_result($stmtPet);
// OPTIONAL STEP: Get the number of rows processed. Skip if you
// do not need to use the number of rows in your code.
// $numberRows = mysqli_affected_rows($dbc);
// OPTIONAL STEP: Debug statement examples. You can do this atan
// at any point for any variable.
// var_dump($numberRows);
// echo "<!-- \$numberRows " . $numberRows . "-->";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Nancy M. - Project View Selected Pet</title>
<?php require("ProjectHeader.php"); ?>
</head>
<body>
<h1>Nancy M. - Project View Selected Pet Details</h1>
<h2>Pet Details</h2>
<?php
// STEP #8: Read rows from the result set. Use a
// while loop if you expect more than one row. Use
// Use an if statement if expecting only one row.
// Include only for SELECT statements. Skip this
// step for INSERT, UPDATE, DELETE, etc.
if($row = mysqli_fetch_array($resultPet)) //only 1 row
{
?>
<table>
<tr>
<td>Pet Microchip ID</td>
<td><?php echo htmlspecialchars($row["MicroChipId"]); ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo htmlspecialChars($row["PetName"]); ?></td>
</tr>
<tr>
<td>Check-In Date</td>
<td><?php echo date("m/d/Y", strtotime($row["CheckInDate"])); ?></td>
</tr>
<tr>
<td>Animal Type</td>
<td><?php echo htmlspecialchars($row["AnimalType"]); ?></td>
</tr>
<tr>
<td>Gender</td>
<td><?php $gender = htmlspecialchars($row["Gender"]);
if($gender == 'F') echo 'Female';
else echo 'Male';
?></td>
</tr>
<tr>
<td>Breed</td>
<td><?php echo htmlspecialchars($row["Breed"]); ?></td>
</tr>
<tr>
<td>Age</td>
<td><?php echo htmlspecialchars($row["Age"]); ?></td>
</tr>
<tr>
<td>Spayed/Neutered</td>
<td><?php $spay = htmlspecialchars($row["SpayedNeuteredNeededFlag"]);
if($spay == 0) echo 'No';
else echo 'Yes';
?></td>
</tr>
<tr>
<td>Shots up to Date</td>
<td><?php $shots = htmlspecialchars($row["ShotsNeededFlag"]);
if ($shots == 0) echo 'No';
else echo 'Yes';
?></td>
</tr>
</table>
<br />
<h2>Veterinarian</h2>
<table>
<tr>
<td>Dr. Name</td>
<td><?php echo $row["DrLastName"] . ", " . $row["DrFirstName"]; ?></td>
</tr>
<tr>
<td>Non-Emergency Phone Number</td>
<td><?php echo substr($row["NonEmergencyPhone"], 0, 3) . "-" . substr($row["NonEmergencyPhone"], 3, 3) . "-" . substr($row["NonEmergencyPhone"], 6, 4) ; ?></td>
</tr>
<tr>
<td>Emergency Phone Number</td>
<td><?php echo substr($row["EmergencyPhone"], 0, 3) . "-" . substr($row["EmergencyPhone"], 3, 3) . "-" . substr($row["EmergencyPhone"], 6, 4) ; ?></td>
</tr>
</table>
<br />
<h2>Pet Owner</h2>
<table>
<tr>
<td>Name</td>
<td><?php echo htmlspecialchars($row["LastName"] . ", " . $row["FirstName"]); ?></td>
</tr>
<tr>
<td>Adoption Date</td>
<td><?php echo date("m/d/Y", strtotime($row["DateOfAdoption"])); ?></td>
</tr>
<tr>
<td>Street Address</td>
<td><?php echo htmlspecialchars($row["StreetAddress"]); ?></td>
</tr>
<tr>
<td>City</td>
<td><?php echo htmlspecialchars($row["City"]); ?></td>
</tr>
<tr>
<td>State</td>
<td><?php echo htmlspecialchars($row["State"]); ?></td>
</tr>
<tr>
<td>Zip Code</td>
<td><?php echo htmlspecialchars($row["ZipCode"]); ?></td>
</tr>
<tr>
<td>Phone Number</td>
<td><?php echo substr($row["PhoneNmbr"], 0, 3) . "-" . substr($row["PhoneNmbr"], 3, 3) . "-" . substr($row["PhoneNmbr"], 6, 4) ; ?></td>
</tr>
<tr>
<td>Previous Pet Experience</td>
<td><?php $exp = htmlspecialchars($row["PreviousPetExp"]);
if($exp == 0) echo 'No';
else echo 'Yes';
?>
</td>
</tr>
<tr>
<td>Dwelling Type</td>
<td><?php $dwelling = htmlspecialchars($row["DwellingType"]);
if($dwelling == 'HOM') echo 'Home';
else if($dwelling == 'APT') echo 'Apartment';
else echo 'Condo';
?>
</td>
</tr>
</table>
<?php
} ?>
<?php
// STEP #9: Close statement(s) and database connection.
mysqli_stmt_close($stmtPet);
mysqli_close($dbc);
?>
<br /><br />
<a href="ProjectDisplayAll.php" class="button">Back to Pet List</a>
<br /><br />
<br /><br />
<?php require("ProjectFooter.php"); ?>
</body>
</html>