我正在创建一个添加好友系统,以便人们可以通过他们的个人资料互相关注。我还没有完成造型,它是纯粹的功能。我的问题如下:'发送邀请'按钮继续显示,尽管邀请已经发送。老实说,我无法弄清楚原因。我在phpmyadmin中测试了查询,它运行正常。这2个用户有一个条目。
以下是查询:
$user_id = $_SESSION['user_id'];
//SEARCH THE USERNAME OF THE LOGGED IN USER
$stmt = $mysqli->prepare("SELECT username, email FROM members WHERE user_id = ? ");
$stmt->bind_param('s', $user_id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($my_username, $my_email);
$stmt->fetch();
$stmt->close();
$username = safe($mysqli,$_GET["username"]);
//LOOK UP THE DETAILS OF THE USERNAME
$stmt = $mysqli->prepare("SELECT user_id, email FROM members WHERE username = ? ");
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($userid, $email);
$stmt->fetch();
$stmt->close();
//Sent invite <---IT KEEPS SAYING THIS EVENTHOUGH THERE'S AN ACTIVE ENTRY
$friendQuery1 = mysqli_query($myqsli,"SELECT * FROM friends WHERE friend_one = '$my_username' AND friend_two = '$username' AND invite_sent = 0 ");
//Invite sent, awaiting acceptance
$friendQuery2 = mysqli_query($myqsli,"SELECT * FROM friends WHERE friend_one = '$my_username' AND friend_two = '$username' AND invite_sent = 1 ");
//Invite accepted. User is friends.
$friendQuery3 = mysqli_query($myqsli,"SELECT * FROM friends WHERE friend_one = '$my_username' AND friend_two = '$username' AND invite_accepted = 1 ");
这是html部分
<body>
DEBUG:
This is the profile page from <b><?php echo $username ?></b><br />
Emailadres: <b><?php echo $email ?></b><br />
<br />
<?php if (login_check($mysqli) == true) : ?>
<?php if (mysqli_num_rows($friendQuery1) == 0) {
echo '<div style="width: 150px; text-align:center; border:1px solid #cecece;">Add friend</div>';
}
if (mysqli_num_rows($friendQuery2) == 1) {
echo '<div style="width: 200px; text-align:center; border:1px solid #cecece;">Invite sent</div>';
}
if (mysqli_num_rows($friendQuery3) == 1) {
echo '<div style="width: 200px; text-align:center; border:1px solid #cecece;">Already Friends</div>';
}
?>
<br>
<br>
<br>
<b>CURRENT LOGGED IN USER: <?php echo $user_id ?> AKA USERNAME: <?php echo $my_username ?></b>
<?php endif; ?>
Bye.
</body>
所以基本上“添加朋友”按钮会继续显示,尽管有一个条目,其中invite_sent设置为“1”。这意味着它应该显示第二个查询,也就是'INVITE SENT'按钮。
我无法弄清楚这里的错误:')
编辑#1 - 安全()功能
function safe($mysqli,$value) {
return mysqli_real_escape_string($mysqli,$value);
}
答案 0 :(得分:0)
我自己解决了。我阅读了代码的每一小部分,并注意到我使用了$ myqsli而不是$ mysqli。因此,它没有显示任何内容。