[insert_php]
$user_id = 0;
$tanggal = 0;
$status = 0;
$action = 0;
if (isset($_POST[“action”])) {
$action = $_POST[“action”];
}
if (isset($_POST[“user_id”])) {
$user_id = $_POST[“user_id”];
}
if (isset($_POST[“tanggal”])) {
$tanggal = $_POST[“tanggal”];
}
if (isset($_POST[“status”])) {
$status = $_POST[“status”];
}
$host = “localhost”; //database location
$user = “mancitic_calenda”; //database username
$pass = “manciti88”; //database password
$db_name = “mancitic_calendar”; //database name
//Database Connection
$connection = mysql_connect($host, $username, $password);
mysql_select_db($dbname);
$conn = get_connection();
if ($conn) {
$query = $conn->query(“insert into Calendar values(‘$user_id’,’$tanggal’,’$status’,’$action’)”);
if ($query) {
http_response_code(201);
} else {
$sql = “UPDATE kalender SET “;
if($status && $action){
$sql .= “status=$status, action=$action”;
} elseif ($status && !$action) {
$sql .= “status=$status”;
} elseif (!$status && $action) {
$sql .= “action=$action”;
}else{
die(500);
}
$sql .= ” where user_id=$user_id and tanggal=$tanggal”;
$query = $conn->query($sql);
if ($query) {
http_response_code(201);
}else die(500);
}
}
[/insert_php]