-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertToLists.php
38 lines (25 loc) · 921 Bytes
/
insertToLists.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
<?php
require "connect.php";
$data = json_decode(file_get_contents("php://input"), true);
$new_list_name = $data['listName'];
$user_email = $data['userEmail'];
///This query just creates a new list with the name provided by the user.
$updateQuery =
"UPDATE user_lists SET list_array = JSON_ARRAY_APPEND(
list_array,
'$',
JSON_OBJECT('list_name', '$new_list_name')
)
WHERE user_email = ?";
// "INSERT INTO user_lists (list_array) VALUES (?) WHERE user_email = ?";
// $arrayToInsert = json_encode(array('list_name' => $new_list_name));
$stmt = $conn -> prepare($updateQuery);
$stmt -> bind_param("s", $user_email);
if ($stmt->execute()) {
header('Content-Type: application/json');
$responseText = json_encode(array('list name' => $new_list_name, 'user email' => $user_email));
echo json_encode($responseText);
} else {
echo 'Error creating a new list. Please try again later.';
}
?>