-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateThreads.php
More file actions
86 lines (56 loc) · 2.57 KB
/
createThreads.php
File metadata and controls
86 lines (56 loc) · 2.57 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
<?php
header("Access-Control-Allow-Origin: *"); // Or specify a domain: 'http://yourdomain.com'
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); // Specify allowed methods
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
// If the request method is OPTIONS, return a 200 status without further processing
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
http_response_code(200);
exit();
}
// Database configuration
$servername = "localhost"; // Database host, usually 'localhost'
$username = "topscbtk_mdev1"; // Database username
$password = "DRT5V+kT_lDo"; // Database password (empty if no password)
$dbname = "topscbtk_mdev1"; // Your database name
// Create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// SQL query to fetch threads where assistant = 'Rahul'
if($_REQUEST['assistant'] && $_REQUEST['thread'])
{
$assistantId = $_REQUEST['assistant'];
$threadId = $_REQUEST['thread'];
$email = $_REQUEST['email'];
$sql_check = "SELECT id FROM threads WHERE thread = ?";
$stmt = $conn->prepare($sql_check);
$stmt->bind_param("s", $threadId);
$stmt->execute();
$result = $stmt->get_result();
// Step 2: If the thread doesn't exist, insert it
if ($result->num_rows == 0) {
if($_REQUEST['verified'] == 1)
{
$sql_insert = "INSERT INTO threads (assistant, thread,email,verified) VALUES ('$assistantId', '$threadId','$email',1)";
}
else{
$sql_insert = "INSERT INTO threads (assistant, thread,email,verified) VALUES ('$assistantId', '$threadId','$email',0)";
}
// Thread does not exist, insert the new thread
$results = $conn->query($sql_insert);
if($results == TRUE)
{
echo json_encode([
'status' => 'success',
'message' => 'Thread created successfully'
]);
} else if($results == FALSE){
// If insertion failed, return an error message in JSON
echo json_encode([
'status' => 'error',
'message' => 'Failed to create thread'
]);
}
}
}