Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this part of code in backend:

if (isset($_GET['publish']) || isset($_GET['unpublish'])) {
$message = "";
if (isset($_GET['publish'])) {
    $message = "Post published successfully";
    $post_id = $_GET['publish'];
} else if (isset($_GET['unpublish'])) {
    $message = "Post successfully unpublished";
    $post_id = $_GET['unpublish'];
}
togglePublishPost($post_id, $message);

}


function togglePublishPost($post_id, $message)
{
global $conn;
$sql = "UPDATE posts SET published=!published WHERE id=$post_id";

if (mysqli_query($conn, $sql)) {
    $_SESSION['message'] = $message;
    header("location: posts.php");
    exit(0);
    }
}

When I try to publish post from "https://....posts.php?publish=36" the page is refreshing and nothing happens. Also there is no logs in error file..Please help me with this..

P.S: the same if I try to unpublish the post. PHP v7.0

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
202 views
Welcome To Ask or Share your Answers For Others

1 Answer

Replace: (!published) with (not published) like this:

$sql = "UPDATE posts SET published = not published WHERE id=$post_id";


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...