我使用html / css和php为我的社交媒体wesbiste设置了关注取消关注按钮。如果我不关注该按钮,则应该打印跟随,我需要能够跟随他。如果我关注该用户,则该按钮应取消打印,而我应取消关注他。
的HTML
<form>
<?php
if ($userid != $followerid) {
if ($isFollowing) {
echo '<input type="submit" name="unfollow" value="unfollow", style="width:100%;background-image:url("none");background-color:#da052b;color:#fff;padding:16px 32px;margin:0px 0px 6px;border:none;box-shadow:none;text-shadow:none;opacity:0.9;text-transform:uppercase;font-weight:bold;font-size:13px;letter-spacing:0.4px;line-height:1;outline:none>';
} else {
echo '<input type="submit" name="follow" value="Follow", style="width:100%;background-image:url("none");background-color:#da052b;color:#fff;padding:16px 32px;margin:0px 0px 6px;border:none;box-shadow:none;text-shadow:none;opacity:0.9;text-transform:uppercase;font-weight:bold;font-size:13px;letter-spacing:0.4px;line-height:1;outline:none>';
}
}
?>
</form>
的PHP
if (isset($_POST['follow'])) {
if ($userid != $followerid) {
if (!DB::query('SELECT follower_id FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=>$userid, ':followerid'=>$followerid))) {
if ($followerid == 6) {
DB::query('UPDATE users SET verified=1 WHERE id=:userid', array(':userid'=>$userid));
}
DB::query('INSERT INTO followers VALUES (null, :userid, :followerid)', array(':userid'=>$userid, ':followerid'=>$followerid));
} else {
echo 'Already following!';
}
$isFollowing = True;
}
}
if (isset($_POST['unfollow'])) {
if ($userid != $followerid) {
if (DB::query('SELECT follower_id FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=>$userid, ':followerid'=>$followerid))) {
if ($followerid == 6) {
DB::query('UPDATE users SET verified=0 WHERE id=:userid', array(':userid'=>$userid));
}
DB::query('DELETE FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=>$userid, ':followerid'=>$followerid));
}
$isFollowing = False;
}
}
if (DB::query('SELECT follower_id FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=>$userid, ':followerid'=>$followerid))) {
$isFollowing = True;
}
当我按下按钮时,它给我一个错误,并且用户发表的所有帖子都消失了,URL更改为:
http://localhost/profile.php?unfollow=unfollow&postbody=&postimg=
最佳答案
可能是您的问题在这里:
<form>
更改为
<form action="somewhere.php" method="post">
添加方法=“发布”
关于javascript - 使用php和html跟随/取消关注按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47733090/