-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_post.php
More file actions
33 lines (32 loc) · 1.04 KB
/
add_post.php
File metadata and controls
33 lines (32 loc) · 1.04 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
<?php
include("./connection.php");
$time = date('Y-m-d H:i:s');
$return_data = array(
"status_code" => "200",
);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$user_id = $_POST["id"];
$title = $_POST["title"];
$class = $_POST['class'];
$user = $_POST['user'];
$content = $_POST['content'];
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$title = $_GET["title"];
$class = $_GET['class'];
$user = $_GET['user'];
$content = $_GET['content'];
}
$class = intval($class);
$post_sql = "INSERT INTO post VALUES(null,'$title','$user','$content',$class,'$time',$user_id)";
$query = mysqli_query($connection, $post_sql);
$insert_id = mysqli_insert_id($connection);
$add_comment_sql = "INSERT INTO comment VALUES(null,'$user','$content','$time',$insert_id,0,$user_id)";
$query = mysqli_query($connection, $add_comment_sql);
if ($query != false) {
echo json_encode($return_data);
} else {
$return_data["status_code"] = 404;
echo json_encode($return_data);
}
// $comment_sql = "INSERT INTO comment VALUES(null,$user,$content)";