forked from Ahamra1120/VoteSphere
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_data.php
More file actions
40 lines (34 loc) · 926 Bytes
/
Copy pathwrite_data.php
File metadata and controls
40 lines (34 loc) · 926 Bytes
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
<?php
require 'koneksi.php';
// Hanya terima POST untuk operasi penulisan
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
header('Allow: POST');
exit('Method Not Allowed');
}
$data = isset($_POST['data']) ? trim($_POST['data']) : '';
if ($data === '') {
http_response_code(400);
exit('Missing data');
}
// Batasi panjang input untuk mencegah abuse
if (strlen($data) > 1024) {
http_response_code(413);
exit('Payload too large');
}
// Prepared statement untuk mencegah SQL injection
$stmt = $koneksi->prepare("INSERT INTO TPS (data) VALUES (?)");
if (!$stmt) {
error_log('Prepare failed: ' . $koneksi->error);
http_response_code(500);
exit('Server error');
}
$stmt->bind_param('s', $data);
if (!$stmt->execute()) {
error_log('Execute failed: ' . $stmt->error);
http_response_code(500);
exit('Server error');
}
http_response_code(201);
echo 'OK';
?>