所以我真的不知道我要在这个上设置标题,通常无法想出任何好的东西。尽管如此,如果您正在阅读本文,我会尽力在此解释。
我正在尝试检查当前登录用户是否等于当前个人资料管理页面上的用户,例如:
目前已登录用户:Bob
如果bob正在查看他自己的个人资料页面,他应该看到一个“编辑”按钮,但是,如果他正在查看“彼得”的个人资料页面,他不应该。我一直在尝试很多不同的方法,我认为可行的方法是使用if会话等于用户名变量,但没有结果。
我正在看的问题是,要么根本不显示任何内容,要么是空白页(除了背景和诸如此类),或者示例中使用的Bob可以访问所有编辑按钮,也不对。
此外,如果有任何用途我现在拥有:
数据库连接:
<?php
// error_reporting(E_ALL);
session_start();
$host = 'HOSTNAME';
$dbusername = 'DATABASENAME';
$dbpassword = 'PASSWORD';
$anslutning = mysqli_connect($host, $dbusername, $dbpassword) or die("<b>Could not connect to database server</b>");
$anslutning->select_db('DATABASE NAME') or die("<b>Could not connect to the specified database</b>");
&GT;
目前的个人资料管理页面:
if(isset($_GET['manage'])) {
$manage = $_GET['manage'];
$editAccount = $anslutning->prepare('SELECT userId, username, email, gender, age, profilePic FROM (tablename) WHERE userId=? LIMIT 1');
$editAccount->bind_param("i", $manage);
$editAccount->bind_result($userId, $username, $email, $gender, $age, $profilePic);
$editAccount->store_result();
$editAccount->execute();
echo '<h2 class="accountm_title">Account management</h2>';
if(isset($_SESSION['loggedIn'])) {
echo '
<i><a class="edit" href="index.php?editAccount='.$userId.'">Edit</a></i>
<hr size="1" width="30%" class="manageHr">
<div class="accountm">
';
}
while($row = $editAccount->fetch()) {
echo '
<form action="index.php" method="GET">
<p>Username: '.$username.' </p>
<p>Email: '.$email.' </p>
<p>Gender: '.$gender.'</p>
<p>Age: '.$age.' </p>
<p>Profile picture: <img src="'.$profilePic.'"></p>
</form>
';
}
}
然后一些代码使用字段更新数据库,这似乎有效。
答案 0 :(得分:0)
用户登录系统后,您将有一个会话来存储userId,这样的个人资料页面如下:http://example.com/editAccount=userId 并且当会话中的userId等于个人资料页面的userId时,您只显示“编辑”按钮。