-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-to-do-item.php
37 lines (29 loc) · 989 Bytes
/
add-to-do-item.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
<?php
include "db_config.php";
$user_id = intval($_POST['user_id']);
$item_id = intval($_POST['item_id']);
$description = $_POST['description'];
$conn = new mysqli($servername, $username, $dbpassword, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Set the appropriate headers to indicate JSON content
// header('Content-Type: application/json');
// Execute SQL queries to fetch users data
$sql = "INSERT INTO todolist (item_id, user_id, description, checked) VALUES ($item_id, $user_id, '$description', 0)";
$result = $conn->query($sql);
/*
// Check if the query was successful
if ($result) {
// Query was successful
$response = array("success" => true, "message" => "Query successful");
} else {
// Query failed
$response = array("success" => false, "message" => "Query failed: " . mysqli_error($conn));
}
echo json_encode($response);
*/
// Close the database connection
$conn->close();
?>