-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbugReport.php
More file actions
56 lines (46 loc) · 1.66 KB
/
bugReport.php
File metadata and controls
56 lines (46 loc) · 1.66 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
<?php
// Include the database connection file
include 'dbconnection.php';
// Get the connection by calling the dbconnection function
$conn = dbconnection();
// Ensure that the connection is established
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Set the response header
header('Content-Type: application/json');
// Initialize an empty response array
$response = array();
// Check if the request method is POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the posted data
$uemail = isset($_POST['uemail']) ? $_POST['uemail'] : '';
$issue_description = isset($_POST['issue_description']) ? $_POST['issue_description'] : '';
// Validate input
if (empty($uemail) || empty($issue_description)) {
$response['status'] = 'error';
$response['message'] = 'Email and issue description are required.';
} else {
// Prepare the SQL statement
$stmt = $conn->prepare("INSERT INTO bug_report (uemail, issue_description) VALUES (?, ?)");
$stmt->bind_param("ss", $uemail, $issue_description);
// Execute the statement
if ($stmt->execute()) {
$response['status'] = 'success';
$response['message'] = 'Bug report submitted successfully.';
} else {
$response['status'] = 'error';
$response['message'] = 'Failed to submit bug report: ' . $stmt->error;
}
// Close the statement
$stmt->close();
}
} else {
$response['status'] = 'error';
$response['message'] = 'Invalid request method.';
}
// Close the database connection
$conn->close();
// Return the response as JSON
echo json_encode($response);
?>