-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_data.php
153 lines (136 loc) · 4.83 KB
/
update_data.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
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
<?php
// Database connection code here (e.g., using PDO or mysqli)
// Function to fetch districts data from the database
function getDistrictsData()
{
// Replace 'your_database_name', 'your_username', 'your_password', and 'your_host' with the actual database credentials
$conn = new PDO("mysql:host=localhost;dbname=sample", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "SELECT * FROM districts";
$stmt = $conn->prepare($query);
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $data;
}
// Function to update district value in the database
function updateDistrictValue($id, $value)
{
// Replace 'your_database_name', 'your_username', 'your_password', and 'your_host' with the actual database credentials
$conn = new PDO("mysql:host=localhost;dbname=sample", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "UPDATE districts SET value = :value WHERE id = :id";
$stmt = $conn->prepare($query);
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$stmt->bindParam(':value', $value, PDO::PARAM_INT);
$stmt->execute();
}
// Update district value if the form is submitted
if (isset($_POST['update'])) {
$id = $_POST['district'];
$value = $_POST['value'];
updateDistrictValue($id, $value);
}
// Fetch districts data from the database
$data = getDistrictsData();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update District Data</title>
<!-- Add Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
background-color: #f8f9fa;
}
/* Add styling for the form */
.update-form {
max-width: 500px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
font-weight: bold;
}
.form-control {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.update-btn {
background-color: #007bff;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
/* Add styling for the "Back to Map" link */
.back-to-map {
text-align: center;
margin-top: 20px;
}
.back-to-map a {
color: #007bff;
text-decoration: none;
}
/* Add styling for the footer */
footer {
background-color: #007bff;
color: #fff;
text-align: center;
padding: 10px 0;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
}
</style>
</head>
<body>
<div class="container mt-5">
<div class="update-form">
<h3 class="mb-4">Update District Data</h3>
<form action="" method="post">
<div class="form-group">
<label for="district-select">Select District:</label>
<select class="form-control" id="district-select" name="district">
<?php foreach ($data as $district) : ?>
<option value="<?php echo $district['id']; ?>">
<?php echo $district['name']; ?> (ID: <?php echo $district['id']; ?>)
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="value-input">Value:</label>
<input type="number" class="form-control" id="value-input" name="value" value="0">
</div>
<button type="submit" class="update-btn" name="update">Update</button>
</form>
<div class="back-to-map">
<a href="index.html">Back to Map</a>
</div>
</div>
</div>
<!-- Add Bootstrap JS (required for dropdown functionality) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Add additional custom scripts if needed -->
</body>
<footer>
<!-- Footer content (if any) -->
</footer>
</html>