-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchooseStateDB2023.php
80 lines (67 loc) · 2.54 KB
/
chooseStateDB2023.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
<?php
// Add require_once function calls as you did in take-home quiz
// Also set up connecting to your database
require_once("included_functions.php");
require_once("database.php");
$mysqli = Database::dbConnect();
$mysqli -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
<!DOCTYPE html>
<html lang="en">
<?php new_header("Pick Your State"); ?>
<form method="POST" action="listStateDB2023.php">
<div class="row">
<label for="left-label" class="left inline">
<h2>Pick Your State</h2>
Choose the Order of Statehood:<select name="ID">
<option></option>
<?php
//******************* Add Code here to choose states *******************
$stmt = $mysqli -> prepare("SELECT * FROM statesS23 ORDER BY Num ASC");
$stmt -> execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
echo"<option value=".$row['Num']."'>".$row["Num"]."</option>";
}
?>
</select><p />
<hr> <b>OR</b> fill in zero or more values below<hr> <p />
<p>State: <input type=text name="name"></p>
<p>State Abbreviation: <input type=text name="abbr"></p>
<p>Capital: <input type=text name="capital"></p>
Start Year:<select name="StartYear">
<option></option>
<?php
$stmt = $mysqli->prepare("SELECT DISTINCT YEAR(Est) AS start_year FROM statesS23 ORDER BY start_year ASC");
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo '<option value="' . htmlspecialchars($row['start_year'], ENT_QUOTES) . '">' . $row['start_year'] . '</option>';
}
?>
</select><p />
End Year:<select name="EndYear">
<option></option>
<?php
$stmt = $mysqli -> prepare("SELECT DISTINCT YEAR(Est) as year FROM statesS23 ORDER BY year DESC");
$stmt -> execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
echo '<option value="'.htmlspecialchars($row['year'], ENT_QUOTES).'">'.$row["year"].'</option>';
}
?>
</select><p />
Flower:<select name="flower">
<option></option>
<?php
$stmt = $mysqli -> prepare("SELECT DISTINCT Flower FROM statesS23 ORDER BY Num ASC");
$stmt -> execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
echo '<option value="'.htmlspecialchars($row['Flower'], ENT_QUOTES).'">'.$row["Flower"].'</option>';
}
?>
<input type="submit" name="submit" class="button tiny round" value="Find a State" />
</label>
</div>
</form>
<?php
new_footer();
Database::dbDisconnect();
?>