-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocations.php
More file actions
93 lines (78 loc) · 2.13 KB
/
Copy pathlocations.php
File metadata and controls
93 lines (78 loc) · 2.13 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
<html>
<head>
<title>Location Management</title>
</head>
<body>
<?php
//This is where our database connection is created, it lives under the variable $conn
include 'header.php';
if (isset($_POST['submit'])) {
openconnection();
$querystring="INSERT INTO location (city,state)
VALUES ('".$_POST['city']."', '".$_POST['state']."');";
//We don't really need to store the result for inserts/deletes, but it helps with debugging
$result = dbquery($querystring);
closeconnection();
//echo $querystring."\n";
}
if(isset($_POST['remove'])) {
if(is_numeric($_POST['remove_id'])){
openconnection();
$querystring = "DELETE FROM location WHERE location_id='".$_POST['remove_id']."';";
//We don't really need to store the result for inserts/deletes, but it helps with debugging
$result = dbquery($querystring);
//Update our relation table
$querystring = "DELETE FROM is_at WHERE location_id='".$_POST['remove_id']."';";
$result = dbquery($querystring);
closeconnection();
}else
echo "<p style='color:red'>Remove ID has to be an integer</p>";
}
?>
<table style="width:100%">
<tr>
<td>
<form action="" method="post">
City:<br>
<input type="text" name="city">
<br>
State:<br>
<input type="text" name="state">
<br>
<input type="submit" value="Add Location" name="submit">
</form>
</td>
<td>
<table border=1>
<tr>
<th>ID</th>
<th>City</th>
<th>State</th>
</tr>
<?php
openconnection();
$sql = "SELECT * FROM location;";
$result = dbquery($sql);
closeconnection();
//This little tidbit right here will loop through the query and print a new row in the table with it's info.
while($resultarray = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>"; print($resultarray['location_id']); echo "</td>";
echo "<td>"; print($resultarray['city']); echo "</td>";
echo "<td>"; print($resultarray['state']); echo "</td>";
echo "</tr>";
}
?>
</tr>
</table>
</td>
<td>
<form action="" method="post">
ID to Remove: <input type="text" name="remove_id">
<input type="submit" value="Remove" name="remove">
</form>
</td
</tr>
</table>
</body>
</html>