1。这是要关注的课程
class Follow extends User {
protected $pdo;
function __construct($pdo){
$this->pdo = $pdo;
}
public function checkFollow($followerID, $user_id){
$stmt = $this->pdo->prepare("SELECT * FROM `follow` WHERE `sender` = :user_id AND `receiver` = :followerID ");
$stmt->bindParam(":user_id", $user_id, PDO::PARAM_INT);
$stmt->bindParam(":followerID", $followerID, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetch(PDO::FETCH_ASSOC);
}
public function followBtn($profileID, $user_id){
$data =$this->checkFollow($profileID, $user_id);
if ($this->loggedIn()===true) {
if ($profileID != $user_id) {
if ($data['receiver'] == $profileID) {
//following btn
echo "<button class='f-btn following-btn follow-btn' data-follow='".$profileID."'>Following</button>";
}else{
//follow btn
echo "<button class='f-btn following-btn follow-btn' data-follow='".$profileID."'><i class='fa fa-user-plus'></i>Follow</button>";
}
}else{
//edit button
echo "<button class='f-btn' onclick=location.href='profileEdit.php'>Edit</button>";
}
}else{
echo "<button class='f-btn' onclick=location.href='index.php'><i class='fa fa-user-plus'></i>Follow</button>";
}
}
}
2。这是我的html代码,如果用户未登录则调用该按钮
<body>
<div class="edit-button">
<span>
<?php $getFromF->followBtn($profileId, $user_id); ?>
</span>
</div>
</body>
它显示这些错误 注意:未定义变量:C:\ xampp \ htdocs \ profile.php
中的getFromF答案 0 :(得分:0)
这是在告诉您您从未定义$getFromF
,并且在您发布的代码中我看不到您这样做。
您需要这样做:
$getFromF = new Follow;
这将实例化您的课程。