Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

php - Publish and unpublish issue

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

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

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...