예제 #1
0
}
function dislike_post($post_id)
{
    global $conn;
    $sql = "update posts set dislikes = dislikes +1 where id = {$post_id}";
    $result = mysqli_query($conn, $sql);
}
switch ($do) {
    case "follow":
        follow_user($_SESSION['userid'], $id);
        $msg = "You have followed a user!";
        break;
    case "unfollow":
        unfollow_user($_SESSION['userid'], $id);
        $msg = "You have unfollowed a user!";
        break;
    case "like":
        like_post($id);
        $msg = "You have liked a post!";
        break;
    case "dislike":
        dislike_post($id);
        $msg = "You have disliked a post!";
        break;
    case "delete":
        delete_post($id);
        $msg = "You have deleted that post!";
        break;
}
$_SESSION['message'] = $msg;
header('Location: /02_welcome.php');
예제 #2
0
<?php

session_start();
include "../config.php";
include "../functions.php";
include "../private_functions.php";
if (isset($_SESSION['auth']) && $_SESSION['auth'] == 1 && isset($_GET['pID'])) {
    $dbh = db_connect($MY_HOST, $MY_DB_PORT, $MY_DB, $DB_USER, $DB_PW);
    if (already_liked($dbh, $_SESSION['user'], $_GET['pID'])) {
        echo json_encode(array("status" => -2));
    } else {
        $res = like_post($dbh, $_SESSION['user'], $_GET['pID']);
        close_db_connection($dbh);
        echo json_encode($res);
    }
} else {
    echo json_encode(array("status" => -1));
}